I am trying to convert this LibGDX example on Animation using a sprite sheet from Java to Kotlin
Here is the link to the Java code snippet:
https://github.com/libgdx/libgdx/wiki/2D-Animation
Here is my Kotlin code:
// load the sprite sheet as a texture
idleSheet = Texture("raw/Skeleton-Idle.png".toInternalFile())
idleFrames = Array<TextureRegion>(true, FRAME_ROWS*FRAME_COLS)
// use split method to create 2d array of texture regions
// sprite sheet contains frames of equal size & alignment
var temp = TextureRegion.split(
idleSheet,
idleSheet.width / FRAME_COLS,
idleSheet.height / FRAME_ROWS
)
var index = 1
for (i in 1..FRAME_ROWS) {
for (j in 1..FRAME_COLS) {
idleFrames[index] = temp[i][j]
index ++
}
}
// initialise animation with frame interval & array of frames
idleAnimation = Animation(0.05f,idleFrames)
The problem seems to be Index 1 out of bounds for length 1
in line idleFrames[index] = temp[i][j]
- I am doing something very basic wrong with Kotlin Arrays but can't seem to fix it.
Any ideas?
question from:
https://stackoverflow.com/questions/65904913/libgdx-animation-java-to-kotlin 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…