SpriteKit .sks Files Crash Xcode 10 When Assigning Texture - ios

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")
}

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.

Related

Does Xcode 11.2 scene editor allow adding components?

Using Xcode 11.2 I can create a new project using the "Game" template. I can include for "Game Technology" SpriteKit and check "Integrate GameplayKit". If I run the code at this point on an iPhone 11 Pro iOS 13.2 simulator I see the "Hello, World!" label. If I go into the Library and add a Color Sprite at position (0,0) to the GameScene.sks file when I run I see the red Color Sprite. My problem comes when I add a Swift file with the content
import GameplayKit
class MovementComponent : GKComponent {
override func update(deltaTime seconds: TimeInterval) {
print(seconds)
}
}
and use the components editor in Xcode to add this component to the Color Sprite. When I run this I get a grey screen. When I check the GameViewController file I see with the debugger that scene.rootNode is nil. What's going wrong? I just want to see how to integrate a component with a Color Sprite using the components editor. Does this stuff work at all or is this just for WWDC demos?
Appears to be a bug in Xcode 11.2. Following the steps above the behavior appears correct for Xcode 10.3. Filled out Apple Feedback FB7427190. Thanks Knight0fDragon for helping identify where the problem was.
I guess my post today is a duplicate of this post.
SKScene not loaded when add GKComponent to GameScene.sks
It seems that the problem still exist in Xcode 11.3.1
If there is no component added in the scene editor to a SKSpriteNode I see that the scene is completely loaded as GameScene.sceneDidLoad is called.
If there is a GKComponent added in the scene editor. The GameScene is not loaded - GameScene.sceneDidLoad is never called.

SpriteKit Scene Images showing as red cross on simulator

I'm having a problem with loading in images onto a scene:
I've added to my project Images/start-button.png (+#2x +#3x)
I've created a new scene: MenuScene.sks
I've added a Sprite object to the scene.
I've selected from the drop down in the texture field "start-button"
On my scene display I can see my Start Game button.
But when I load the simulator I get:
SKTexture: Error loading image resource: "start-button"
Simulator Preview:
These images are not oversized (about 300x150) and they load programatically in my scene using:
SKSpriteNode(imageNamed: "Images/start-button")
Does anyone know what I've done wrong here?
Many thanks!
Drag and drop start-button.png into the Assets.xcassets area and try running the simulator again

swift file not linked to sks file and not changing

So I have a game so far and everything seems to be working very well. I'm only using the basic gamescreen.swift that is default project along with the .sks file for it as well. After a certain condition is met (opponent winning by certain amount of points), it transitions to the .sks file. I even double checked by removing the .sks file to see if it was maybe just transitioning to the .swift file but when I did that I got the nil error (for obvious reasons).
So when I do things like (below) on the .swift file it should theoretically change the .sks file and how it looks visually when I build, but it doesn't. Nothing happens
var background = SKSpriteNode(imageNamed: "theimage")
override func didMove(to view: SKView) {
background.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
addChild(background)
}
So then I remove everything from the .swift file and instead manually add the image to the .sks file and it doesn't do a single thing when I build it.
So I'm thinking, maybe it's just not even showing the .sks file, but rather a random thing. So I changed the background of the .sks file and built it and the change occurred. I made sure I checked with multiple colors and it didn't work. I just was wondering why if I manually add image to the .sks it's not working yet when I change background image it does...hm
Next time if anyone encounters this make sure that the image you're trying to add as a node isn't significantly large. That was my issue but when I resized the image it all worked out :D

Problems with .ccb file for sprite in SpriteBuilder

I am trying to understand SpriteBuilder. I made a new file hero.ccb for sprite and set it's sprite frame to the image I need. When I go back to the MainScene and drag hero.ccb from the left menu,there is just a CCBFile without anything(no sprite image). What am I doing wrong?
This can happen if you didn't save the hero.ccb. Choose File -> Save All or simply Publish the project to have SpriteBuilder update all references.

XCode Has No Option to Enable Texture Atlas Generation

I'm following along with this apple doc, but for some reason when I search for "Sprite" under Build Settings in XCode nothing pops up. I've also tried searching for "Enable Texture Atlas Generation" and nothing comes up.
I have Xcode 5.0.2 if that helps.
The SPRITEKIT_TEXTURE_ATLAS_OUTPUT settings will be there in a new project but the SpriteKit Deployment Options will be created later. Of course you must select SpriteKit Game template when you create the project.
These settings added automatically to your project when you add the first texture atlas resource to it. You need to add a folder named with the .atlas extension. For example you have textures for your hero the atlas should be named as hero.atlas.
I was bedeviled by this exact issue for the past day, when I discovered that if I add an atlas to the project by dragging and dropping, the Sprite Kit Texture Atlas Options were not added to the Build Settings. If I chose File > Add Files to... from the menu bar, however, the Sprite Kit Texture Atlas Options appeared in the Build Settings.
So, apparently, do not drag and drop to add a texture atlas.

Resources