sprite/sheet
This commit is contained in:
parent
a7ff475b91
commit
23ce690549
3 changed files with 9 additions and 12 deletions
|
@ -24,10 +24,9 @@ func init() {
|
|||
type Sprite struct {
|
||||
ID
|
||||
Actor
|
||||
FrameSize image.Point
|
||||
FrameOffset image.Point
|
||||
Hidden
|
||||
Src ImageRef
|
||||
Sheet Sheet
|
||||
ZOrder
|
||||
|
||||
anim *Anim
|
||||
|
@ -43,18 +42,14 @@ func (s *Sprite) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
|||
geom.Concat(opts.GeoM)
|
||||
opts.GeoM = geom
|
||||
|
||||
frame := s.anim.CurrentFrame()
|
||||
src := s.Src.Image()
|
||||
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)
|
||||
src := s.Sheet.SubImage(s.anim.CurrentFrame())
|
||||
screen.DrawImage(src, &opts)
|
||||
}
|
||||
|
||||
func (s *Sprite) Scan() []interface{} {
|
||||
return []interface{}{
|
||||
&s.Actor,
|
||||
&s.Src,
|
||||
&s.Sheet,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
6
main.go
6
main.go
|
@ -18,7 +18,7 @@ func main() {
|
|||
ebiten.SetWindowSize(640, 480)
|
||||
ebiten.SetWindowTitle("TODO")
|
||||
|
||||
if true {
|
||||
if false {
|
||||
writeLevel1()
|
||||
}
|
||||
|
||||
|
@ -140,11 +140,13 @@ func writeLevel1() {
|
|||
},
|
||||
ZOrder: 3,
|
||||
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"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := engine.SaveGobz(level1, "game/assets/level1.gobz"); err != nil {
|
||||
|
|
Loading…
Reference in a new issue