sprite framesize/frameoffset
This commit is contained in:
parent
89461950e2
commit
702774be37
2 changed files with 12 additions and 7 deletions
|
@ -14,6 +14,8 @@ func init() {
|
|||
// Sprite combines an Actor with the ability to Draw from a single spritesheet.
|
||||
type Sprite struct {
|
||||
Actor
|
||||
FrameSize image.Point
|
||||
FrameOffset image.Point
|
||||
Hidden bool
|
||||
ID
|
||||
Src ImageRef
|
||||
|
@ -27,15 +29,16 @@ func (s *Sprite) Draw(screen *ebiten.Image, geom ebiten.GeoM) {
|
|||
return
|
||||
}
|
||||
var op ebiten.DrawImageOptions
|
||||
op.GeoM.Translate(float64(s.Pos.X), float64(s.Pos.Y))
|
||||
dp := s.Pos.Add(s.FrameOffset)
|
||||
op.GeoM.Translate(float64(dp.X), float64(dp.Y))
|
||||
op.GeoM.Concat(geom)
|
||||
|
||||
frame := s.anim.CurrentFrame()
|
||||
src := s.Src.Image()
|
||||
w, _ := src.Size()
|
||||
sp := image.Pt((frame*s.Size.X)%w, ((frame*s.Size.X)/w)*s.Size.Y)
|
||||
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.Size)}).(*ebiten.Image), &op)
|
||||
screen.DrawImage(src.SubImage(image.Rectangle{sp, sp.Add(s.FrameSize)}).(*ebiten.Image), &op)
|
||||
}
|
||||
|
||||
func (s *Sprite) Scan() []interface{} { return []interface{}{&s.Actor} }
|
||||
|
|
4
main.go
4
main.go
|
@ -73,8 +73,10 @@ func main() {
|
|||
Actor: engine.Actor{
|
||||
CollisionDomain: "level_1",
|
||||
Pos: image.Pt(100, 100),
|
||||
Size: image.Pt(10, 16),
|
||||
Size: image.Pt(8, 16),
|
||||
},
|
||||
FrameOffset: image.Pt(-1, 0),
|
||||
FrameSize: image.Pt(10, 16),
|
||||
Src: engine.ImageRef{Path: "assets/aw.png"},
|
||||
ZPos: 2,
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue