How can I make cocos2d schedule selector only once? Right now the best I can do is:
[self schedule:@selector(eventHappend:) interval:2];
and eventHappend:
- (void)eventHappend: (ccTime) dt
{
[self unschedule:@selector(eventHappend:)];
// Do stuff
}
but that seems like a workaround... is there a method to schedule only once?
You can run a sequence of actions on the node, a CCDelay followed by a CCCallFunc that invokes your method.
Like this...
[self runAction:[CCSequence actions:[CCDelayTime actionWithDuration:2],
[CCCallFunc actionWithTarget:self selector:@selector(eventHappened)],
nil]];
- (void) scheduleOnce: (SEL)selector delay: (ccTime)delay
Schedules a selector that runs only once, with a delay of 0 or larger
http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_node.html#afe99d609f17c4c849e4543805ffeceab
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With