From cf4ab7e36afada6881bec52edb9fbe9058c8507c Mon Sep 17 00:00:00 2001 From: faiface Date: Wed, 25 Jan 2017 19:55:41 +0100 Subject: [PATCH] fix Sprite.SetPicture --- graphics.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/graphics.go b/graphics.go index 0a310ed..ee14c96 100644 --- a/graphics.go +++ b/graphics.go @@ -185,6 +185,11 @@ func NewSprite(pic *Picture) *Sprite { // SetPicture changes the Picture of the Sprite and resizes it accordingly. func (s *Sprite) SetPicture(pic *Picture) { + oldPic := s.pic + s.pic = pic + if oldPic.Bounds().Size == pic.Bounds().Size { + return + } w, h := pic.Bounds().Size.XY() (*s.data)[0].Position = V(0, 0) (*s.data)[2].Position = V(w, h) @@ -192,7 +197,7 @@ func (s *Sprite) SetPicture(pic *Picture) { (*s.data)[3].Position = V(0, 0) (*s.data)[4].Position = V(w, h) (*s.data)[5].Position = V(0, h) - s.pic = pic + s.td.dirty = true } // Picture returns the current Picture of the Sprite.