SpriteKit Scene Images showing as red cross on simulator - ios

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

Related

SpriteKit - SKScene bounds are not equal to SKView bounds

Recently I've created a new Xcode - Game project. Without touching anything I ran the template. I was expecting a standard Hello World! app, but I noticed one thing. Instead of pretty filled background, I got scene cut at the top and the bottom.
How can I make it fill the whole screen?
It looks like the default SpriteKit Game template is missing a Launch Screen. You need to add it manually:
Add a Launch Screen:
New File -> iOS -> User Interface -> Launch Screen
Set the name of your new launch screen in:
[Your Project] -> General -> Launch Screen File

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 .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:
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.

Spritekit scene editor size

I am trying to get into the sprite kit scene editor that recently came out, and having some difficulties. My main problem is that i can't seem to understand the size of it.
The current size is 1024 x 768. So i start adding nodes to it, and then run it as an iPhone app, and now it won't show my nodes. They simple get left out since it resizes it. My problem is, i thought it would handle this automatically (scale it to fit), but it doesn't.
so my question is, how do you handle this? I mean Apple has a lot of different screen sizes now, so how on earth are one supposed to match this? Surely you aren't supposed to create an entire scene for each screen size, there must be a better way? I just have no clue. I thought this code would take care of it (standard code when making a new spriteKit project) in the GameViewController that presents the scene:
// Create and configure the scene.
GameScene *scene = [GameScene unarchiveFromFile:#"GameScene"];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
But it doesn't. It displays it all if i'm running it on an iPad in landscape mode, but not if i switch to portrait or run in any iPhone orientation.
So how do you support multiple screen sizes with this new editor? And if anyone can point me to a resource where i can learn more about this editor i would be thrilled.
Thanks in advance,
Best Regards,
/JBJ

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.

Resources