Pergunta

I am using last version of cocos2d. I'd like remove few sprites from parent. There would usually be sequence used, right? But in my case it would be easier to remove sprites after some time, so I am trying to set a timer.

I tried this `

 [self schedule:@selector(oneTimer) interval:5.0f repeat:0 delay:3];

and then

-(void)oneTimer{
[self removeChild:_abcd];
[self removeChild:_abce];
[self removeChild:_aabcd];
[self removeChild:_aaabcd];

}

I don't get what I wanted. How should it be realized? So that "oneTimer" method would be called only once?

Foi útil?

Solução

If you want to run oneTimer() only once after a delay of 3 seconds then you can use performselector_after_delay or scheduleOnce_delay which will run only once. e.g.

   [self performSelector:@selector(oneTimer) withObject:nil afterDelay:3];

OR

   [self scheduleOnce:@selector(oneTimer) delay:3];

Outras dicas

Scheduled selectors take a time parameter, so:

[self schedule:@selector(oneTimer:) and so on...];

Notice the dolon at the end of the selector name, because the method signature must be:

-(void) oneTimer:(CCTime)deltaTime {
    ..
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top