feat: added a few new parameters to add gapping for reading from images.

This commit is contained in:
Andrey Parhomenko 2024-01-16 07:49:56 +03:00
parent 8fcb1c2dc5
commit 7b9025b062
2 changed files with 4 additions and 3 deletions

View file

@ -36,7 +36,7 @@ type AnimationId int
type AnimationSet map[AnimationId] Animation
func AnimationSetFromImage(
img *Image,
w, h int,
w, h, gx, gy int,
defines ...AnimationDefine,
) (AnimationSet, error) {
set := AnimationSet{}
@ -50,8 +50,8 @@ func AnimationSetFromImage(
idx := define.Indexes[i]
animation[i] = ebiten.NewImageFromImage(img.SubImage(
ImageRect{
Min: ImagePoint{idx.X*fw, idx.Y*fh},
Max: ImagePoint{(idx.X+1)*fw, (idx.Y+1)*fh},
Min: ImagePoint{idx.X*fw+gx, idx.Y*fh+gy},
Max: ImagePoint{(idx.X+1)*fw-gx, (idx.Y+1)*fh-gy},
},
))
}

View file

@ -55,6 +55,7 @@ func main() {
playerAnimations, _ = gg.AnimationSetFromImage(
playerImg,
8, 3,
10, 1,
gg.AD(Stand).DefRow(0, 0, 1, 2, 3, 4),
gg.AD(Walk).DefRow(1, 0, 1, 2, 3, 4, 5, 6, 7),
)