While I know my redSprite doesn't fulfill all the if's in the touch functions, I'm placing a breakpoint at the start of the touch functions, and it still won't stop at the breakpoint.
However...if I set GameScene's isUserInteractionEnabled to true, then I do get the touches and the debugger breaks.
Code Block import UIKit import SpriteKit var redSprite : SKSpriteNode? class GameScene: SKScene, SKPhysicsContactDelegate { override func sceneDidLoad(){ super.sceneDidLoad() #if DEBUG print ("GC sceneDidLoad") #endif } override func didMove(to view: SKView){ super.didMove(to: view) #if DEBUG print ("GC didMove START") #endif self.isHidden = true self.backgroundColor = mySafeColor myGlobalVars.backGround = SKSpriteNode(imageNamed: "background") myGlobalVars.backGround!.zPosition = theZ.backGround myGlobalVars.safeSceneRect = view.frame myGlobalVars.gameScene = self self.isHidden = false self.isUserInteractionEnabled = false self.addChild(myGlobalVars.backGround!) physicsWorld.contactDelegate = self redSprite = SKSpriteNode(color: .red, size: CGSize(width: 100, height: 100)) redSprite?.anchorPoint = CGPoint(x: 0.5, y:0.5) redSprite?.isHidden = false redSprite?.isUserInteractionEnabled = true redSprite?.color = .orange redSprite!.name = "test" redSprite?.zPosition = 10 redSprite?.position = CGPoint(x: (myGlobalVars.safeSceneRect.width/2)-(50), y: myGlobalVars.safeSceneRect.height/2 - 50) redSprite?.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: 100, height: 100), center: CGPoint(x: 0.5, y: 0.5)) redSprite?.physicsBody!.affectedByGravity = false redSprite?.physicsBody!.restitution = 0.2 redSprite?.physicsBody?.categoryBitMask = bodyMasks.blankMask.rawValue redSprite?.physicsBody?.contactTestBitMask = bodyMasks.blankMask.rawValue redSprite?.physicsBody?.collisionBitMask = bodyMasks.blankMask.rawValue self.addChild(redSprite!) gameTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: true) gameTimer?.tolerance = 0.2 RunLoop.current.add(gameTimer!, forMode: .common) #if DEBUG print ("GC didMove END") #endif } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ guard let touch = touches.first else { return } let location = touch.location(in: self) let touchedNodes = self.nodes(at: location) for node in touchedNodes{ if let theNode = node as? MyGem { if theNode.nodeType == NodeType.gem, theNode.isMoving == false { theNode.isMoving = true theNode.zPosition += 1 myGlobalVars.currentGem = theNode } } } } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){ guard touches.first != nil else { return } if let touch = touches.first, let node = myGlobalVars.currentGem, node.isMoving == true { let touchLocation = touch.location(in: self) node.position = touchLocation node.isMoving = true node.inSlot = false //addTrailToTwinkle(theNode: node) } } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { guard touches.first != nil else { return } if let _ = touches.first, let node = myGlobalVars.currentGem, node.isMoving == true { returnHome(moveThis : node, origNP: node.origPoint) } } override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) { guard touches.first != nil else { return } if let _ = touches.first, let node = myGlobalVars.currentGem, node.isMoving == true { returnHome(moveThis : node, origNP: node.origPoint) } } @objc func runTimedCode() { timeLeft -= 1 } }
See discussion here:
https://stackoverflow.com/questions/5887305/uiview-user-interaction-enabled-false-on-parent-but-true-on-child
userInteractionEnabled set to NO on a parent view will cascade down to all subviews. If you need some subviews to have interaction enabled, but not others, you can separate your subviews into two parent views: one with userInteractionEnabled = YES and the other NO.