문제

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?

도움이 되었습니까?

해결책

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];

다른 팁

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 {
    ..
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top