slightly optimize Sprite.SetPicture
This commit is contained in:
parent
4824154027
commit
6874fff0f6
|
@ -20,6 +20,13 @@ func NewSprite(pic Picture) *Sprite {
|
||||||
// SetPicture changes the Sprite's Picture. The new Picture may have a different size, everything
|
// SetPicture changes the Sprite's Picture. The new Picture may have a different size, everything
|
||||||
// works.
|
// works.
|
||||||
func (s *Sprite) SetPicture(pic Picture) {
|
func (s *Sprite) SetPicture(pic Picture) {
|
||||||
|
oldPic := s.d.Picture
|
||||||
|
s.d.Picture = pic
|
||||||
|
|
||||||
|
if oldPic.Bounds() == pic.Bounds() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bounds = pic.Bounds()
|
bounds = pic.Bounds()
|
||||||
center = bounds.Center()
|
center = bounds.Center()
|
||||||
|
@ -41,7 +48,6 @@ func (s *Sprite) SetPicture(pic Picture) {
|
||||||
}
|
}
|
||||||
|
|
||||||
s.d.Dirty()
|
s.d.Dirty()
|
||||||
s.d.Picture = pic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Picture returns the current Sprite's Picture.
|
// Picture returns the current Sprite's Picture.
|
||||||
|
|
Loading…
Reference in New Issue