fix Sprite for changing Picture bounds

This commit is contained in:
faiface 2017-03-08 19:19:02 +01:00
parent 0127a8ae21
commit 5a9c43bc6c
1 changed files with 8 additions and 8 deletions

View File

@ -2,8 +2,9 @@ package pixel
// Sprite is a drawable Picture. It's always anchored by the center of it's Picture.
type Sprite struct {
tri *TrianglesData
d Drawer
tri *TrianglesData
bounds Rect
d Drawer
}
// NewSprite creates a Sprite from the supplied Picture.
@ -20,18 +21,17 @@ func NewSprite(pic Picture) *Sprite {
// SetPicture changes the Sprite's Picture. The new Picture may have a different size, everything
// works.
func (s *Sprite) SetPicture(pic Picture) {
oldPic := s.d.Picture
s.d.Picture = pic
if oldPic != nil && oldPic.Bounds() == pic.Bounds() {
if s.bounds == pic.Bounds() {
return
}
s.bounds = pic.Bounds()
var (
bounds = pic.Bounds()
center = bounds.Center()
horizontal = V(bounds.W()/2, 0)
vertical = V(0, bounds.H()/2)
center = s.bounds.Center()
horizontal = V(s.bounds.W()/2, 0)
vertical = V(0, s.bounds.H()/2)
)
(*s.tri)[0].Position = -horizontal - vertical