Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Commit

Permalink
common: generate atlas in y rather than x direction (#126)
Browse files Browse the repository at this point in the history
This lets us generate atlases that are more "square"ish,
and thus less likely to hit the graphics card boundaries
for texture dimensions.

Fixes #121.
  • Loading branch information
mewmew authored and essial committed Nov 10, 2019
1 parent 948ca1f commit 09e713b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions common/Sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,29 @@ func CreateSprite(data []byte, palette PaletteRec) *Sprite {
totalHeight := 0
frame := 0
for d := 0; d < int(result.Directions); d++ {
curMaxHeight := 0
curMaxWidth := 0
for f := 0; f < int(result.FramesPerDirection); f++ {
totalWidth += int(result.Frames[frame].Width)
curMaxHeight = int(Max(uint32(curMaxHeight), result.Frames[frame].Height))
curMaxWidth = int(Max(uint32(curMaxWidth), result.Frames[frame].Width))
totalHeight += int(result.Frames[frame].Height)
frame++
}
totalHeight += curMaxHeight
totalWidth += curMaxWidth
}
result.atlas, _ = ebiten.NewImage(totalWidth, totalHeight, ebiten.FilterNearest)
result.atlasBytes = make([]byte, totalWidth*totalHeight*4)
frame = 0
curX := 0
curY := 0
for d := 0; d < int(result.Directions); d++ {
curMaxHeight := 0
curMaxWidth := 0
for f := 0; f < int(result.FramesPerDirection); f++ {
curMaxHeight = int(Max(uint32(curMaxHeight), result.Frames[frame].Height))
curMaxWidth = int(Max(uint32(curMaxWidth), result.Frames[frame].Width))
result.Frames[frame].Image = result.atlas.SubImage(image.Rect(curX, curY, curX+int(result.Frames[frame].Width), curY+int(result.Frames[frame].Height))).(*ebiten.Image)
curX += int(result.Frames[frame].Width)
curY += int(result.Frames[frame].Height)
frame++
}
curY += curMaxHeight
curX = 0
curX += curMaxWidth
curY = 0
}
return result
}
Expand Down

0 comments on commit 09e713b

Please sign in to comment.