i’ve faced up with cocos2d engine, which is great by the way…
few days ago i was need to understand, when you run action, how detect if it is still running or just stopped..
so, i’ve read their documentation, but didn’t get how to do that according docs. So i’ve decided to make it through system scheduler, that is the same as NSTimer in core iphone objective c. We make our scheduler run and then release it when animation is stopped.
for example, we have object which we need to rotate. how to find out, when the rotation circle is over?
yes, we need to use step function, which give us understanding if it is still running ‘1‘ or not ‘0‘
- (void)StartAnim:(BOOL)direction Duration:(int)dur { if (direction) { id rightRotation = [RotateBy actionWithDuration:dur angle:360]; [object runAction:rightRotation]; } else { id leftRotation = [RotateBy actionWithDuration:dur angle:-360]; [object runAction:leftRotation]; } [self schedule: @selector(update:) interval:0.5]; } - (void)update: (ccTime) time { if ([object step_:0.5] == 1) { [self start]; } else if ([object step_:0.5] == 0) { [self stop]; [self unschedule:@selector(update:)]; } } - (void)start { NSLog(@"start"); } - (void)stop { NSLog(@"stop"); }


No Comments on "cocos2d runAction: animStart/animStop"