Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit .sks Files Crash Xcode 10 When Assigning Texture

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:

    green square

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

enter image description here

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

enter image description here

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")
}
like image 470
Neil Hiddink Avatar asked Sep 25 '18 04:09

Neil Hiddink


1 Answers

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.

like image 143
刘用法 Avatar answered Nov 20 '22 06:11

刘用法