sprite/sheet

This commit is contained in:
Josh Deprez 2021-08-26 13:57:19 +10:00
parent a7ff475b91
commit 23ce690549
3 changed files with 9 additions and 12 deletions

View file

@ -24,10 +24,9 @@ func init() {
type Sprite struct { type Sprite struct {
ID ID
Actor Actor
FrameSize image.Point
FrameOffset image.Point FrameOffset image.Point
Hidden Hidden
Src ImageRef Sheet Sheet
ZOrder ZOrder
anim *Anim anim *Anim
@ -43,18 +42,14 @@ func (s *Sprite) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
geom.Concat(opts.GeoM) geom.Concat(opts.GeoM)
opts.GeoM = geom opts.GeoM = geom
frame := s.anim.CurrentFrame() src := s.Sheet.SubImage(s.anim.CurrentFrame())
src := s.Src.Image() screen.DrawImage(src, &opts)
w, _ := src.Size()
sp := image.Pt((frame*s.FrameSize.X)%w, ((frame*s.FrameSize.X)/w)*s.FrameSize.Y)
screen.DrawImage(src.SubImage(image.Rectangle{sp, sp.Add(s.FrameSize)}).(*ebiten.Image), &opts)
} }
func (s *Sprite) Scan() []interface{} { func (s *Sprite) Scan() []interface{} {
return []interface{}{ return []interface{}{
&s.Actor, &s.Actor,
&s.Src, &s.Sheet,
} }
} }

Binary file not shown.

View file

@ -18,7 +18,7 @@ func main() {
ebiten.SetWindowSize(640, 480) ebiten.SetWindowSize(640, 480)
ebiten.SetWindowTitle("TODO") ebiten.SetWindowTitle("TODO")
if true { if false {
writeLevel1() writeLevel1()
} }
@ -140,11 +140,13 @@ func writeLevel1() {
}, },
ZOrder: 3, ZOrder: 3,
FrameOffset: image.Pt(-1, 0), FrameOffset: image.Pt(-1, 0),
FrameSize: image.Pt(10, 16), Sheet: engine.Sheet{
CellSize: image.Pt(10, 16),
Src: engine.ImageRef{Path: "assets/aw.png"}, Src: engine.ImageRef{Path: "assets/aw.png"},
}, },
}, },
}, },
},
} }
if err := engine.SaveGobz(level1, "game/assets/level1.gobz"); err != nil { if err := engine.SaveGobz(level1, "game/assets/level1.gobz"); err != nil {