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.


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"


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 == "pineapple"

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




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.