i have object on screen app launches. have method randomly starts placing more of same object when app launches, want happen after app registers touch. how can that? think have in touches began method, can't seem code working.
this 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 out of this.
here 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() } }
in viewdidload() method add following code:
self.view.addgesturerecognizer(uitapgesturerecognizer(self, "viewtapped:")) then implement following method:
func viewtapped(recognizer: uitapgesturerecognizer) { call method here self.view.removegesturerecognizer(uitapgesturerecognizer(self, "viewtapped:")) } this means tap registered anywhere on screen, method called.
Comments
Post a Comment