2D Apple Games by Tutorial - SKSpriteNodes

Hello,

I´m new to Xcode and Swift and I just bought me the book “2D Apple Games by Tutorial”

My problem in Chapter1:Sprites is by displaying de background1 image as a SKSpriteNode into the scene.
I added all the images into the Assets Catalog but when running the simulator the App doesn’t show the background. Is that because my Xcode can’t load the png file from the Assets?

Here is my code, exactly like in the book:

import SpriteKit

class GameScene: SKScene {

override func didMove(to view: SKView) {
    backgroundColor = SKColor.black
    
    let background = SKSpriteNode(imageNamed: "background1")
    background.position = CGPoint(x: size.width/2, y: size.height/2)
    addChild(background)
}

}

please help me with this issue, I´m pretty desperate, because there is no solution to this on the internet.

ok, just fixed it.

i deleted my Xcode project and started a new one… luckily now it works, don’t know what I had done wrong…

@thedarksebi Glad you managed to work it out! Cheers!

This topic was automatically closed after 166 days. New replies are no longer allowed.