Alec52 Alec52 - 2 months ago 11
Swift Question

Error when switching scenes through a button node

I'm trying to switch scenes when you press a button, however, when I click it, nothing happens, and nothing gets printed. There are no errors, I am just wondering why it is not working.
The node that I programmed DOES show up at the correct size and location, but when you tap on it nothing goes through. Thank you for any help.

Code:

class LevelScene: SKScene, SKPhysicsContactDelegate {

var isFingerOnBlock = false
let LevelOneName = "levelOne"

override func didMove(to view: SKView) {
super.didMove(to: view)
let Pineapple = SKSpriteNode(imageNamed: "ball")
Pineapple.isUserInteractionEnabled = true
Pineapple.position = CGPoint(x: self.frame.midX - 200, y: self.frame.midY);
Pineapple.name = "pineapple"
addChild(Pineapple)

}





func touchesBegan(touches: NSSet, withEvent event: UIEvent)
{
let touch = touches.anyObject() as! UITouch
let location = touch.location(in: self)
let nodes = self.nodes(at: location)

for node in nodes
{
if node.name == "pineapple"
{
print("ceeds")

if let scene = GameScene(fileNamed:"GameScene") {
// Configure the view.
let skView = self.view!
skView.showsFPS = true
skView.showsNodeCount = true

/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true

/* Set the scale mode to scale to fit the window */
scene.scaleMode = .aspectFit

skView.presentScene(scene)


}
break
}
}
}

}

Answer Source

You have declared

func touchesBegan(touches: NSSet, withEvent event: UIEvent)

There is no built-in function with that signature, and you never call that function; therefore your function is never called.