我正在尝试使用Sprite表将Java上的LibGDX示例转换为动画到Kotlin
这是Java代码段的链接:https : //github.com/libgdx/libgdx/wiki/2D-Animation
这是我的Kotlin代码:
// 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)
问题似乎Index 1 out of bounds for length 1
符合要求idleFrames[index] = temp[i][j]
-我在用Kotlin Arrays做一些非常基本的错误,但似乎无法解决。
有任何想法吗?
..
是包容的。直到结束独占。
数组从索引0而不是1开始。因此,请使用i in 0 until FRAME_ROWS
。
libGDX Array类的行为很像List。您无法将值直接分配给尚未填写的索引。因此,代替idleFrames[index] = temp[i][j]
使用idleFrames.add(temp[i][j])
,您可以index
完全摆脱变量。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句