1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-02 17:27:23 -04:00
OpenDiablo2/d2core/d2gui/sprite.go
Alex Yatskov 6f2c212417
Continued work on GUI (#316)
* Configuration cleanup

* Cleanup

* Continued UI work
2020-02-24 22:35:21 -05:00

48 lines
998 B
Go

package d2gui
import (
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2asset"
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
)
type Sprite struct {
widgetBase
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
}
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)
}
func (s *Sprite) advance(elapsed float64) error {
return s.animation.Advance(elapsed)
}
func (s *Sprite) getSize() (int, int) {
return s.animation.GetCurrentFrameSize()
}