cocos2d-iphonerotationcclayerccrotateby

Determine if CCLayer is currently rotating


I'm rotating an instance of a CCLayer subclass like this:

[self runAction:[CCRotateBy actionWithDuration:0.5 angle:180.0]];

This rotating is in response to a user tap (which may come rapidly). How can I determine if the layer is currently being rotating? In this case I can just ignore the tap.


Solution

  • When declaring your CCAction, it is possible to set a tag attribute to it, and then retrieve the action by using getActionByTag. If the returning value is not nil, then it means that the action is actually running.

    CCRotateBy *rotate = [CCRotateBy actionWithDuration:1.0 angle:100];
    rotate.tag = 100;
    [myNode runAction:rotate];
    if ([myNode getActionByTag:100]) {
        NSLog(@"Rotating!!");
    }