ios - How to spawn a node on a scheduled timer loop in a override touch began method -


so creating shooting game ios , having trouble looping bullet spawn method activated touching , moving joystick. i've tried seems coding there right way.

here bullet defined:

 func spawnbullet1(){     self.addchild(bullet1)     bullet1.position = cgpoint (x: gun1.position.x , y:       gun1.position.y) // bullet spawn @ anchor point     bullet1.xscale = 0.5     bullet1.yscale = 0.5     //physics, not important right      bullet1.physicsbody = skphysicsbody(rectangleofsize: bullet1.size)     bullet1.physicsbody?.categorybitmask = physicscategory.bullet1     bullet1.physicsbody?.contacttestbitmask = physicscategory.enemy1     bullet1.physicsbody?.affectedbygravity = false     bullet1.physicsbody?.dynamic = false     let wait:skaction = skaction.waitforduration(0.5) //bullet spawn wait     let block:skaction = skaction.runblock(spawnbullet1) //re-spawn bullet     let seq3:skaction = skaction.sequence( [ wait, block ]) //sequence     self.runaction(seq3) //execution    } 

my joystick in touches begins here:

 override func touchesbegan(touches: set<uitouch>, withevent     event:uievent?) {      touch in touches {         let location = touch.locationinnode(self)         let node = nodeatpoint(location)         if (cgrectcontainspoint(joystick.frame, location)) {             stickactive = true          }else{             stickactive = false         }          if stickactive == true {             spawnbullet1()         } 

obviously left out details joystick because that's not part i'm having trouble with. problem having first bullet launches planned , works great, however, when second bullet spawned app crashes, saying cannot add sknode when node has parent or that, saying duplicating bullet wrong way , can't figure out right way is.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -