mirror of
https://github.com/curioustorvald/Terrarum-sans-bitmap.git
synced 2026-06-16 10:34:04 +09:00
Font implementation for GDX (issue #4), various format changes on the spritesheets
This commit is contained in:
45
terrarumsansbitmap/gdx/TextureRegionPack.kt
Normal file
45
terrarumsansbitmap/gdx/TextureRegionPack.kt
Normal file
@@ -0,0 +1,45 @@
|
||||
package net.torvald.terrarumsansbitmap.gdx
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-06-15.
|
||||
*/
|
||||
class TextureRegionPack(
|
||||
val texture: Texture,
|
||||
val tileW: Int,
|
||||
val tileH: Int,
|
||||
val hGap: Int = 0,
|
||||
val vGap: Int = 0,
|
||||
val hFrame: Int = 0,
|
||||
val vFrame: Int = 0
|
||||
) {
|
||||
|
||||
val regions: Array<TextureRegion>
|
||||
|
||||
private val horizontalCount = (texture.width - 2 * hFrame + hGap) / (tileW + hGap)
|
||||
private val verticalCount = (texture.height - 2 * vFrame + vGap) / (tileH + vGap)
|
||||
|
||||
init {
|
||||
//println("texture: $texture, dim: ${texture.width} x ${texture.height}, grid: $horizontalCount x $verticalCount, cellDim: $tileW x $tileH")
|
||||
|
||||
regions = Array<TextureRegion>(horizontalCount * verticalCount, {
|
||||
val region = TextureRegion()
|
||||
val rx = (it % horizontalCount * (tileW + hGap)) + hFrame
|
||||
val ry = (it / horizontalCount * (tileH + vGap)) + vFrame
|
||||
|
||||
region.setRegion(texture)
|
||||
region.setRegion(rx, ry, tileW, tileH)
|
||||
|
||||
/*return*/region
|
||||
})
|
||||
}
|
||||
|
||||
fun get(x: Int, y: Int) = regions[y * horizontalCount + x]
|
||||
|
||||
fun dispose() {
|
||||
texture.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user