1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-17 09:56:07 -05:00
OpenDiablo2/d2core/d2gui/sprite.go

48 lines
998 B
Go
Raw Normal View History

2020-02-08 21:02:37 -05:00
package d2gui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
type Sprite struct {
widgetBase
2020-02-08 21:02:37 -05:00
segmentsX int
segmentsY int
frameOffset int
animation *d2asset.Animation
}
func createSprite(imagePath, palettePath string) (*Sprite, error) {
animation, err := d2asset.LoadAnimation(imagePath, palettePath)
if err != nil {
return nil, err
}
sprite := &Sprite{}
sprite.animation = animation
sprite.SetVisible(true)
return sprite, nil
2020-02-08 21:02:37 -05:00
}
func (s *Sprite) SetSegmented(segmentsX, segmentsY, frameOffset int) {
s.segmentsX = segmentsX
s.segmentsY = segmentsY
s.frameOffset = frameOffset
}
func (s *Sprite) render(target d2render.Surface) error {
return renderSegmented(s.animation, s.segmentsX, s.segmentsY, s.frameOffset, target)
2020-02-08 21:02:37 -05:00
}
func (s *Sprite) advance(elapsed float64) error {
return s.animation.Advance(elapsed)
}
func (s *Sprite) getSize() (int, int) {
return s.animation.GetCurrentFrameSize()
}