-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspritesheet.go
More file actions
35 lines (27 loc) · 779 Bytes
/
Copy pathspritesheet.go
File metadata and controls
35 lines (27 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package ebitenloader
import (
"image"
"github.com/hajimehoshi/ebiten/v2"
)
// ParseSprites parses a spritesheet into an array of it's sub-sprites.
//
// spN - number of sprites you want to parse
//
// spWidth & spHeight - dimensions of each individual sprite in pixels
//
// sheetWidth - width of the spritesheet measured in sprite lengths
func ParseSprites(src *ebiten.Image, spN, spWidth, spHeight, sheetWidth int) []*ebiten.Image {
var sprites []*ebiten.Image
for i := range spN {
column := i % sheetWidth
row := i / sheetWidth
x0 := column * spWidth
y0 := row * spHeight
x1 := x0 + spWidth
y1 := y0 + spHeight
rect := image.Rect(x0, y0, x1, y1)
subImg := src.SubImage(rect).(*ebiten.Image)
sprites = append(sprites, subImg)
}
return sprites
}