shooting intervals in cocos2d without CACurrentMediaTime() -


i have ship , want make shoot every 1 sec. here's did,

@property (nonatomic, assign) float lastdamagetime; 

and in update method,

if (cacurrentmediatime - self.lastdamagetime > 1) {     self.lastdamagetime = cacurrentmediatime;     [self shoot]; } 

but problem is, pause game right after ship shoot bullet, , 1 sec later, resume game, if statement pass check, , ship shoot bullet immediately. , that's not want.

so, can make sure ship fire bullets each sec weather pause game or not? should use cctimer instead?

thank in advance answer.

you try , schedule shoots ccrepeatforever action, cocos2d deals pause you. it'd (assuming you're inside custom shipsprite).-

ccdelaytime *delay = [ccdelaytime actionwithduration:1.0]; cccallfunc *funcshoot = [cccallfunc actionwithtarget:self selector:@selector(shoot)]; ccrepeatforever *repeat = [ccrepeatforever actionwithaction:[ccsequence actionone:delay two:funcshoot]]; [self runaction:repeat]; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -