slightly optimize Sprite.SetPicture

This commit is contained in:
faiface 2017-03-08 00:43:01 +01:00
parent 4824154027
commit 6874fff0f6
1 changed files with 7 additions and 1 deletions

View File

@ -20,6 +20,13 @@ 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.Bounds() == pic.Bounds() {
return
}
var (
bounds = pic.Bounds()
center = bounds.Center()
@ -41,7 +48,6 @@ func (s *Sprite) SetPicture(pic Picture) {
}
s.d.Dirty()
s.d.Picture = pic
}
// Picture returns the current Sprite's Picture.