I have an object on screen as soon as the app launches. I have a method that randomly starts placing more of that same object when the app launches, but I want that to happen after the app registers a touch. How can I do that? I think it would have to be something in my touches began method, but I can't seem to get my code working.
This is what I did after Jacob's post:
func viewdidload() {
self.view!.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "viewTapped:"))
}
func viewTapped(recognizer: UITapGestureRecognizer) {
func spawnObject()
self.view!.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "viewTapped:"))
}
I think I'm missing something out of this.
Here is my touches began method: override func touchesBegan(touches: Set, withEvent event: UIEvent) {
if let touch = touches.first as? UITouch {
if self.touch == false {
self.touch = true
self.spawnObjects()
}
}
if !ball.physicsBody!.dynamic {
startGameTextNode.removeFromParent()
ball.physicsBody!.dynamic = true
}
if (moving.speed > 0) {
ball.physicsBody!.velocity = CGVectorMake(0, 0)
ball.physicsBody!.applyImpulse(CGVectorMake(0, 8))
} else if (canRestart) {
self.resetScene()
}
}