Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Sometimes I find the interop between Kotlin and libGDX (Java really) a bit odd, but when it comes together, it really does make for a lot less boilerplate:

var firing = Texture(Assets.TURRET_ANIMATION)
var tmp = TextureRegion.split(firing, firing.width, firing.height/10)
var firingFrames = Array<TextureRegion>(10, { i -> tmp[i][0] })
var firingAnimation = Animation(0.02f, *firingFrames)

testAnim.add(AnimationComponent(firingAnimation))


Here I'm trying out animations using a sprite sheet. This works in this instance because I only have one column in the sheet, hence mapping it straight into a 1 dimensional array.

I struggled a little with the Animation constructor because I thought I needed a badlogic.Array, I had a Kotlin array and couldn't get them to play nice together. Turns out Animation will take a varargs TextureRegion as argument which Kotlin's spread (*) operator will let us do from an Array.

Neato!