SpriteKit .sks Files Crash Xcode 10 When Assigning Texture

别等时光非礼了梦想. 提交于 2019-12-04 18:14:15

问题


Am I missing something obvious?

For reasons unknown, Xcode 10 keeps crashing on me when I go to assign a texture to a named sprite using the Scene Editor. After having to delete and recreate my .sks files a couple times, I decided to try and reproduce the issue using Xcode's game template. The steps I took to do this are as follows:

  • Open Xcode and select Create a new Xcode project.
  • Choose the Game template, name the project Test and save it somewhere, i.e. your desktop.
  • Drag any image asset into Assets.xcassets. I used this green square:

  • Open GameScene.sks and drag a Color Sprite onto the scene.

  • Name the sprite something descriptive like square_green.
  • Attempt to set the texture in this field:

Other similar questions on Stack Overflow:

Xcode is crashing in SpriteKit

XCode 9 Crashing while setting a Texture in SKScene in Spritekit

If I do not set a name for the color sprite prior to assigning a texture, everything works fine. However, if Xcode is forced to crash at least one time, I have to delete the .sks file completely just to get Xcode to open again.

For the time being I've decided to avoid the trouble all together and just assign the textures programmatically in the didMove(to:) of my SKScene class:

override func didMove(to view: SKView) {
    let greenSquare = childNode(withName: "square_green") as! SKSpriteNode
    greenSquare.texture = SKTexture(imageNamed: "square_green")
}

回答1:


I ran into the same problem, and later I moved the images out of Assets.xcassets and the problem was solved. I guess the image can't be placed in Assets.xcassets.



来源:https://stackoverflow.com/questions/52490578/spritekit-sks-files-crash-xcode-10-when-assigning-texture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!