Trevor Thomas
Trevor Thomas

Reputation: 79

Xcode touchesEnded stops working

I am writing an app with Xcode and swift. I am using SpriteKit's SKScene. I am having a super interesting error. I have a class Level1 and inside it, I have the touchesEnded method, and it works for about 2 or so clicks, and then it just stops. I have a simple print("hello world") in it, and it prints it twice, then stops. I don't really know what to attach for this error, so I have attached the method and the superclass method

import SpriteKit

class Level1: LevelBase {

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesEnded(touches, with: event)
        print("Hello world")
    }
}

and

import SpriteKit

class LevelBase: SKScene, SKPhysicsContactDelegate {

      override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        for touch in touches {
            let location = touch.location(in: self)

            for node in nodes(at: location) {
                if node.name == "planet" {
                    moveAroundPlanet(planet: node as! SKSpriteNode)
                }
            }
        }
    }
}

I am adding Level1 from another scene using this

var scene = SKScene()
scene = Level1(fileNamed: "Level1")!
scene.scaleMode = .aspectFill
self.scene?.view?.presentScene(scene)

Let me know if any additional code is needed

Upvotes: 1

Views: 50

Answers (0)

Related Questions