SKTextures未加载到iPod Touch上的阵列中

时间:2023-01-22 23:17:34

I am having a really weird problem with my SpriteKit Game. It works perfectly fine on my iPad and on the iOS simulators, but when I run it on my iPod Touch, there is an error. I located where the error was coming from, and it is here, where I try to access one of the items in an array of textures:

我的SpriteKit游戏有一个非常奇怪的问题。它在我的iPad和iOS模拟器上运行得非常好,但是当我在iPod Touch上运行时,出现错误。我找到了错误来自的地方,就在这里,我尝试访问纹理数组中的一个项目:

let firstFrame = Frames[0]

The error is basically saying that Frames[0] doesn't exist, and indeed, on iPod Touch, when I print the number of items in the array, there is nothing. On the other devices, the array has all the textures it should have.

错误基本上是说Frames [0]不存在,事实上,在iPod Touch上,当我打印数组中的项目数时,什么都没有。在其他设备上,数组具有应该具有的所有纹理。

Here is where and how I am loading some textures from a texture atlas into the array for an animation:

以下是我将纹理图集中的一些纹理加载到动画数组中的位置和方式:

let birdAtlas = SKTextureAtlas(named: "bird")   
    var Frames = [SKTexture]() ////Here is the array into which I am loading textures

    let numImages = birdAtlas.textureNames.count  ////Should be 12, as is on devices other than iPod
    print(numImages) ////On iPod Touch, numImages = 0

    for var i=1; i<=numImages/3; i++ {

        let birdTextureName = "\(currentBird)\(i)"
        print(birdTextureName)
        Frames.append(birdAtlas.textureNamed(birdTextureName))

    } //^^This loop adds the textures 1 - 4 to the array

    for var i=numImages/3; i>=1; i-- {

        let birdTextureName = "\(currentBird)\(i)"
        print(birdTextureName)
        Frames.append(birdAtlas.textureNamed(birdTextureName))

    } //^^This loop adds the textures 3 - 1 to the array

When this is run on any other device than the iPod Touch, the textures in my atlas load into the array Frames. However, on the iPod Touch, no textures are loaded into the array. Here is an image of the texture atlas: link to image of texture array

当它在除iPod Touch之外的任何其他设备上运行时,我的地图集中的纹理会加载到阵列帧中。但是,在iPod Touch上,没有纹理加载到阵列中。这是纹理图集的图像:链接到纹理数组的图像

Again, the textures load into the array perfectly and animates perfectly on iPad and iPhone simulators, as well as a real iPad device. It just doesn't work on iPod Touch, and the error is causing the app not to be able to load. The iPod touch is running iOS 9, just like the other devices.

再次,纹理完美地加载到阵列中,并在iPad和iPhone模拟器以及真正的iPad设备上完美地动画。它只是在iPod Touch上不起作用,错误导致应用程序无法加载。 iPod touch正在运行iOS 9,就像其他设备一样。

Any help is appreciated! Thanks!

任何帮助表示赞赏!谢谢!

1 个解决方案

#1


1  

Since my previous comment does fix the problem I'm posting it as an answer along with a more detailed explanation.

由于我之前的评论确实解决了问题,我将其作为答案发布,并附上更详细的解释。

Creating a Sprite Atlas in Xcode 7

  1. Open the Project Navigator pressing cmd + 1
  2. 按cmd + 1打开Project Navigator

  3. Select Assets.xcassets
  4. In the main area right click on the left column and select New Sprite Atlas
  5. 在主区域中右键单击左列并选择New Sprite Atlas

  6. Now a Sprites folder has appeared, just drag images from the Finder to this folder to populate your Sprite Atlas.
  7. 现在出现了一个Sprites文件夹,只需将图像从Finder拖到此文件夹即可填充Sprite Atlas。

SKTextures未加载到iPod Touch上的阵列中

#1


1  

Since my previous comment does fix the problem I'm posting it as an answer along with a more detailed explanation.

由于我之前的评论确实解决了问题,我将其作为答案发布,并附上更详细的解释。

Creating a Sprite Atlas in Xcode 7

  1. Open the Project Navigator pressing cmd + 1
  2. 按cmd + 1打开Project Navigator

  3. Select Assets.xcassets
  4. In the main area right click on the left column and select New Sprite Atlas
  5. 在主区域中右键单击左列并选择New Sprite Atlas

  6. Now a Sprites folder has appeared, just drag images from the Finder to this folder to populate your Sprite Atlas.
  7. 现在出现了一个Sprites文件夹,只需将图像从Finder拖到此文件夹即可填充Sprite Atlas。

SKTextures未加载到iPod Touch上的阵列中