Mina
Mina

Reputation: 2212

Switch from UIViewController to SKSCene doesn't show anything

I've started to create a battle game with Spritekit.

I have a splash screen and main menu. I used UIViewController to create these two pages and SKScene to create a game scene. Now in MainMenu I want to switch to GameScene in Play button action but the GameScene doesn't show anything. I have break points in GameScene, and surprisingly all the codes in didMoveToView is running but my page dent switch to GameScene and I am still in MainMenu.

I used the following code to switch from uiviewcontroller to game scene:

@IBAction func playButton(sender: UIButton) {

    let scene = GameScene(size:view.bounds.size)//(fileNamed: "GameScene") {
    let skView = self.view as! SKView
    skView.showsFPS = true
    skView.showsNodeCount = true
    skView.ignoresSiblingOrder = true
    scene.scaleMode = .AspectFill
    skView.presentScene(scene)


}

the

override func didMoveToView(view: SKView) {
    /* Setup your scene here */
    let myLabel = SKLabelNode(fontNamed:"Chalkduster")
    myLabel.text = "Hello, World!"
    myLabel.fontSize = 45
    myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))

    self.addChild(myLabel)
}

is running and I can navigate to it by break points.

Upvotes: 0

Views: 185

Answers (1)

Mina
Mina

Reputation: 2212

Finally i found the problem. I had to remove all the objects like UIImages, Buttons, Labels,... from superview. like this :

       for view in self.view.subviews {
        view.removeFromSuperview()
       }

They didn't let the GameScene Nodes to be presented.

Upvotes: 1

Related Questions