Cocos2d仅调度一次

问题描述

| 如何仅使cocos2d计划选择器一次?现在,我能做的最好的事情是:
[self schedule:@selector(eventHappend:) interval:2];
eventHappend:
- (void)eventHappend: (ccTime) dt
{
    [self unschedule:@selector(eventHappend:)];
    // Do stuff
}
但这似乎是一种解决方法...是否有只安排一次的方法?     

解决方法

        您可以在节点上运行一系列动作,先是CCDelay,然后是调用您的方法的CCCallFunc。 像这样...
[self runAction:[CCSequence actions:[CCDelayTime actionWithDuration:2],[CCCallFunc actionWithTarget:self selector:@selector(eventHappened)],nil]];
    ,        
- (void) scheduleOnce: (SEL)selector delay: (ccTime)delay 
安排仅运行一次的选择器,延迟为0或更大 http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_node.html#afe99d609f17c4c849e4543805ffeceab     ,        您还可以使用以下命令:
[self unschedule:_cmd];
在eventHappened Function中-将使您的计划运行一次。     ,        其中大多数对于您所需要的而言过于复杂(即使它们非常简单) 您所需要做的只是以下代码行:
[self performSelector:@selector(eventHappend:) withObject:nil afterDelay:2];
它将只运行一次eventHappend方法。