我正试图调用一个函数,其中包含ccactioninterval in Cocos3d。我想以特定的时间间隔呼叫该功能。当我尝试NSTimer时,我发现它有时可用,有时不起作用。在iOS中调用特定时间间隔的动作
NSTimer makeTarget=[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(createTargets) userInfo:nil repeats:YES];
这里createTargets是包含动作事件的函数。当我运行函数时,可以单次工作。当我尝试安排它时,问题就来了。我已经尝试了不同的方法已经解释了相关的问题。但没有为我工作。 。 。 。
下面是代码
-(void) addTargets {
NSTimer *makeTarget = [NSTimer scheduledTimerWithTimeInterval:2.0
target:self selector:@selector(createTargets) userInfo:nil repeats:YES];
}
-(void)createTargets {
CC3MeshNode *target = (CC3MeshNode*)[self getNodeNamed: @"obj1"];
int minVal=-5;
int maxVal=5;
float avgVal;
avgVal = maxVal- minVal;
float Value = ((float)arc4random()/ARC4RANDOM_MAX)*avgVal+minVal ;
[target setLocation:cc3v(Value, 5.0, 0.0)];
CCActionInterval *moveTarget = [CC3MoveBy actionWithDuration:7.0 moveBy:cc3v(0.0, -10.0, 0.0)];
CCActionInterval *removeTarget = [CCCallFuncN actionWithTarget:self selector:@selector(removeTarget:)];
[target runAction:[CCSequence actionOne:moveTarget two:removeTarget]];
}
-(void)removeTarget:(CC3MeshNode*)targ {
[self removeChild:targ];
targ=nil;
}
你还试过什么,什么都不起作用。你尝试过CCTimer吗? – Wain
我试过调度器和cctimer。已拨打电话但未执行操作 –
如果已拨打电话但未执行操作,我会说问题出在操作上,请显示该代码。 – Wain