Cui Longchang
Cui Longchang

Reputation: 23

How can I switch scenes in SceneKit when clicking a SpriteKit overlay label?

I am stuck on this problem.

I laid a SpriteKit node over a SceneKit Scene. I'm trying to use SpriteKit to display labels and those labels switch scenes when touched. Imagine "Game Start", "Quit", "Shop" as buttons.

But it doesn't work.

How should I switch scenes in SceneKit from interaction with SpriteKit labels?

GameStart image

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    /* Called when a touch begins */
    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        let touchNode:SKNode = self.nodeAtPoint(location)
        if(touchNode.name == "elementButton"){
            //let scene = ElementsScene(size: self.size)
            self.view?.presentScene(scene)
        } else if (touchNode.name == "classicButton"){
            //let scene = ClassicScene(size: self.size)
            self.view?.presentScene(scene)
        } else if (touchNode.name == "quitButton"){
            //Quit Game
        }
    }

Upvotes: 2

Views: 734

Answers (1)

Toyos
Toyos

Reputation: 4064

The API for scene transition is the following (ObjC version):

- (void)presentScene:(SCNScene *)scene withTransition:(SKTransition *)transition incomingPointOfView:(nullable SCNNode *)pointOfView completionHandler:(nullable void (^)())completionHandler NS_AVAILABLE(10_11, 9_0);

"presentScene" with just one argument doesn't exist.

Upvotes: 3

Related Questions