mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-10-04 09:15:09 -04:00
common: generate atlas in y rather than x direction (#126)
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.
This commit is contained in:
parent
948ca1fc1a
commit
09e713b1cb
@ -141,13 +141,13 @@ func CreateSprite(data []byte, palette PaletteRec) *Sprite {
|
|||||||
totalHeight := 0
|
totalHeight := 0
|
||||||
frame := 0
|
frame := 0
|
||||||
for d := 0; d < int(result.Directions); d++ {
|
for d := 0; d < int(result.Directions); d++ {
|
||||||
curMaxHeight := 0
|
curMaxWidth := 0
|
||||||
for f := 0; f < int(result.FramesPerDirection); f++ {
|
for f := 0; f < int(result.FramesPerDirection); f++ {
|
||||||
totalWidth += int(result.Frames[frame].Width)
|
curMaxWidth = int(Max(uint32(curMaxWidth), result.Frames[frame].Width))
|
||||||
curMaxHeight = int(Max(uint32(curMaxHeight), result.Frames[frame].Height))
|
totalHeight += int(result.Frames[frame].Height)
|
||||||
frame++
|
frame++
|
||||||
}
|
}
|
||||||
totalHeight += curMaxHeight
|
totalWidth += curMaxWidth
|
||||||
}
|
}
|
||||||
result.atlas, _ = ebiten.NewImage(totalWidth, totalHeight, ebiten.FilterNearest)
|
result.atlas, _ = ebiten.NewImage(totalWidth, totalHeight, ebiten.FilterNearest)
|
||||||
result.atlasBytes = make([]byte, totalWidth*totalHeight*4)
|
result.atlasBytes = make([]byte, totalWidth*totalHeight*4)
|
||||||
@ -155,15 +155,15 @@ func CreateSprite(data []byte, palette PaletteRec) *Sprite {
|
|||||||
curX := 0
|
curX := 0
|
||||||
curY := 0
|
curY := 0
|
||||||
for d := 0; d < int(result.Directions); d++ {
|
for d := 0; d < int(result.Directions); d++ {
|
||||||
curMaxHeight := 0
|
curMaxWidth := 0
|
||||||
for f := 0; f < int(result.FramesPerDirection); f++ {
|
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)
|
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++
|
frame++
|
||||||
}
|
}
|
||||||
curY += curMaxHeight
|
curX += curMaxWidth
|
||||||
curX = 0
|
curY = 0
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user