You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
849 B
Go
44 lines
849 B
Go
package component
|
|
|
|
import (
|
|
"time"
|
|
|
|
"code.rocketnine.space/tslocum/monovania/engine"
|
|
|
|
"code.rocketnine.space/tslocum/gohan"
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
)
|
|
|
|
type SpriteComponent struct {
|
|
Image *ebiten.Image
|
|
HorizontalFlip bool
|
|
VerticalFlip bool
|
|
DiagonalFlip bool // TODO unimplemented
|
|
|
|
Overlay *ebiten.Image
|
|
OverlayX, OverlayY float64 // Overlay offset
|
|
|
|
Frame int
|
|
Frames []*ebiten.Image
|
|
FrameTime time.Duration
|
|
LastFrame time.Time
|
|
NumFrames int
|
|
|
|
OverrideColorScale bool
|
|
ColorScale float64
|
|
}
|
|
|
|
var SpriteComponentID = engine.Engine.NewComponentID()
|
|
|
|
func (p *SpriteComponent) ComponentID() gohan.ComponentID {
|
|
return SpriteComponentID
|
|
}
|
|
|
|
func Sprite(ctx *gohan.Context) *SpriteComponent {
|
|
c, ok := ctx.Component(SpriteComponentID).(*SpriteComponent)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return c
|
|
}
|