From 540f285468e5a05d5815e79b85c3bff1b920493f Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Sat, 19 Dec 2020 21:05:41 +0100 Subject: [PATCH] fixed onHover bug in d2ui.Sprite (#992) Co-authored-by: M. Sz --- d2core/d2ui/sprite.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/d2core/d2ui/sprite.go b/d2core/d2ui/sprite.go index 7c66e1fd..ba2a369d 100644 --- a/d2core/d2ui/sprite.go +++ b/d2core/d2ui/sprite.go @@ -34,17 +34,25 @@ func (ui *UIManager) NewSprite(animationPath, palettePath string) (*Sprite, erro base := NewBaseWidget(ui) - return &Sprite{ + sprite := &Sprite{ BaseWidget: base, animation: animation, Logger: ui.Logger, - }, nil + } + + sprite.SetVisible(false) + + ui.addWidget(sprite) + + return sprite, nil } // Render renders the sprite on the given surface func (s *Sprite) Render(target d2interface.Surface) { _, frameHeight := s.animation.GetCurrentFrameSize() + s.width, s.height = s.animation.GetCurrentFrameSize() + target.PushTranslation(s.x, s.y-frameHeight) defer target.Pop() @@ -90,11 +98,6 @@ func (s *Sprite) RenderSegmented(target d2interface.Surface, segmentsX, segments } } -// GetSize returns the size of the current frame -func (s *Sprite) GetSize() (width, height int) { - return s.GetCurrentFrameSize() -} - // GetFrameSize gets the Size(width, height) of a indexed frame. func (s *Sprite) GetFrameSize(frameIndex int) (x, y int, err error) { return s.animation.GetFrameSize(frameIndex)