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 {
|
2020-02-17 22:11:52 -05:00
|
|
|
widgetBase
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
segmentsX int
|
|
|
|
segmentsY int
|
|
|
|
frameOffset int
|
|
|
|
|
|
|
|
animation *d2asset.Animation
|
|
|
|
}
|
|
|
|
|
2020-02-24 22:35:21 -05:00
|
|
|
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 {
|
2020-02-24 22:35:21 -05:00
|
|
|
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)
|
|
|
|
}
|
2020-02-17 22:11:52 -05:00
|
|
|
|
|
|
|
func (s *Sprite) getSize() (int, int) {
|
|
|
|
return s.animation.GetCurrentFrameSize()
|
|
|
|
}
|