1

我正在尝试将一堆动画纹理从纹理图集中加载到数组中,但是在尝试将帧附加到数组时出现错误。

基本上我想要一个多维纹理数组,其中每一行代表一个动画,它是一个帧数组。像这样的东西:

[[FirstFrameTexture, SecondFrameTexture, ThirdFrameTexture...], //first animation
 [FirstFrameTexture, SecondFrameTexture, ThirdFrameTexture...], //second animation
 [FirstFrameTexture, SecondFrameTexture, ThirdFrameTexture...]] //third animation

我初始化了一个这样的数组:

var animations = [[SKTexture]]()

但是当我尝试像这样将纹理附加到数组中时

animations[0].append(SKTexture(imageNamed: "test"))

我在这一行收到一条错误消息:

fatal error: Cannot index empty buffer

关于如何解决这个问题的任何想法?

4

1 回答 1

0

当您尝试向其附加动画时,尚未创建索引为 0 的第一个数组。

首先添加一个嵌入数组的动画,例如:

animations.append([SKTexture(imageNamed: "test")])

然后你可以在数组中添加动画:

animations[0].append(SKTexture(imageNamed: "test2"))
于 2015-03-22T11:53:24.063 回答