1
votes

I am very new to Swift and iOS development. I was watching tutorials on iOS development w/ Swift and SpriteKit. Following the tutorials I opened Xcode, new project, game, universal; and all I changed was the GameScene.swift. Here is the new code:

import SpriteKit

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        /* Setup your scene here */
        var node1 = SKNode()
        node1.position = CGPoint(x: 100, y: 100)
        self.addChild(node1)

        var spr1 = SKSpriteNode(imageNamed: "Spaceship")
        spr1.position = CGPointZero
        spr1.zPosition = 1
        node1.addChild(spr1)
    }

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        /* Called when a touch begins */
    }

    override func update(currentTime: CFTimeInterval) {
        /* Called before each frame is rendered */
    }
}

Note: the Spaceship image is provided by default.

So in the tutorials, this code added a spaceship to the scene. However, when I run the simulator, the scene remains blank. What can be the problem? If more info is needed, please say so and I will provide.

2
Is GameScene being presented?l00phole
Show your GameViewController.swift code.Dharmesh Kheni
The GameScene is presented, and the code is being run. I confirmed it with debugging.J164
I did not change GameViewController.swift. It is whatever it is by default.J164
Any errors? Works fine for me. (Spaceship is loaded - hanging off the bottom left of the screen)Matt Le Fleur

2 Answers

1
votes

It could be running correctly, and you just can't see it on the screen. Depending on the device that you're emulating, you may be showing the spaceship off screen. Try a different, smaller device, to emulate, and check if you can see it.

0
votes

Try going into your GameViewController.swift and making sure that you see something along the lines of this:

class GameViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        if let scene = GameScene(fileNamed:"GameScene") {
            let skView                 = self.view as! SKView
            skView.showsFPS            = true
            skView.showsNodeCount      = true
            skView.ignoresSiblingOrder = true

            scene.scaleMode = .AspectFill
            scene.size      = skView.bounds.size

            skView.presentScene(scene)
        }
    }
}