fixed onHover bug in d2ui.Sprite (#992)

Co-authored-by: M. Sz <mszeptuch@protonmail.com>
This commit is contained in:
gucio321 2020-12-19 21:05:41 +01:00 committed by GitHub
parent a4a7c8d7e7
commit 540f285468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 7 deletions

View File

@ -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)