Пример #1
0
func (s *Sprite) Draw(view views.View) {

	frame, ok := s.frames[s.frame]
	if !ok {
		return
	}
	styles := frame.styles
	runes := frame.runes
	if runes == nil {
		return
	}
	offx, offy := s.posx-s.originx, s.posy-s.originy
	for y := 0; y < s.height; y++ {
		for x := 0; x < s.width; x++ {
			i := y*s.width + x
			if len(runes) < i {
				return
			}
			if runes[i] == 0 {
				continue
			}
			style := tcell.StyleDefault
			if len(styles) >= i {
				style = styles[i]
			}
			view.SetContent(x+offx, y+offy,
				runes[i], nil, style)
		}
	}
}
Пример #2
0
func (m *SpriteManager) Draw(v views.View) {

	v.Clear()

	m.forAll(func(s *Sprite) { s.Draw(v) })
}