ios - Spawning SkShapeNodes with NSTimer Swift -


i creating game in sprite kit , spawn enemies on screen @ intervals. of right now, code run crashes timer supposed preform action, giving me error message thread 1: exc_bad_access (code=1, address=0x0). here code trying enact.

        func randomelement() -> skshapenode! {         let index = int(arc4random_uniform(uint32(arrayofenemies.count)))         return arrayofenemies[index] as! skshapenode     }      func randomelement2() -> skshapenode! {         let index = int(arc4random_uniform(uint32(arrayofenemies2.count)))         return arrayofenemies2[index] as! skshapenode     }      func randomelement3() -> skshapenode! {         let index = int(arc4random_uniform(uint32(arrayofenemies3.count)))         return arrayofenemies3[index] as! skshapenode     }      func randomelement4() -> skshapenode! {         let index = int(arc4random_uniform(uint32(arrayofenemies4.count)))         return arrayofenemies4[index] as! skshapenode     }      let addenemy = randomelement()      let addenemy2 = randomelement2()      let addenemy3 = randomelement3()      let addenemy4 = randomelement4()       func addallenemies() {         self.addchild(addenemy)         self.addchild(addenemy2)         self.addchild(addenemy3)         self.addchild(addenemy4)     }      var enemy = nstimer.scheduledtimerwithtimeinterval(3.0, target: self, selector: selector(addallenemies()), userinfo: nil, repeats: true) 

at start of game, 4 of random enemies spawn , supposed do. 3 seconds later, when timer set restart function, game crashes. appreciated. thanks!

if creating game sprite-kit, best way integrate timers in project use skaction instead of nstimer

skaction.waitforduration(some value) 

if want repeat forever can use

skaction.repeatactionforever(your action) 

after that, can create custom function called when timer ends through skaction.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -