CCActionDelay not working as expected

82 views Asked by At

What I have is a method that creates CCSprites:

-(void)createDebrisAtPosition:(CGPoint)position{
    NSInteger numberOfPieces = [random randomWithMin:5 max:20];
    for (int i=0; i<numberOfPieces; i++) {
        CCSprite *debris = [CCSprite spriteWithImageNamed:@"debri.png"];
        debris.position = position;
        debris.physicsBody = [CCPhysicsBody bodyWithRect:CGRectMake(0, 0, debris.contentSize.width, debris.contentSize.height) cornerRadius:0];
        debris.physicsBody.collisionType = @"debris";
        debris.name = @"Debris";
        CCActionRemove *removeAction = [CCActionRemove action];
        CCActionSequence *sequence = [CCActionSequence actions:[CCActionDelay actionWithDuration:2.0], removeAction, nil];
        [physics addChild:debris];
//physics is a CCPhysicsNode here
        [debris runAction:sequence];
    }
}

This method then gets invoked during specific collision events:

-(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair enemy:(EnemyNode*)enemy projectile:(ProjectileNode*)projectile
{
    [enemy removeFromParent];
    [projectile removeFromParent];
    [self createDebrisAtPosition:enemy.position];
    return NO;
}

Expected behavior: CCSprites should appear and then get removed only after 2.0 secs. Actual behavior: CCSprites appear for a split-second, then instantly get removed.

I also tried CCActionInterval, CCActionEaseOut, but they didn't work (And they shouldn't, according to the docs, but CCActionDelay — should, but not working). I changed the order of method invocation (runAction after and before addChild), as well as the order of action invocation this didn't work as well. Don't mind the CCActionDelay declaration directly in the CCActionSequence — I tried to declare it as a separate variable, with zero luck.

What am I misunderstanding here?

1

There are 1 answers

0
Pontus Armini On

I'm new here so I'm not allowed to comment yet (this would perhaps be better suited as a comment) but: I haven't been able to recreate your problem. The problem is not related to CCActionDelay or the actions you are running on the debris sprite. You can test this yourself by running your sequence in a different setup. Ergo: there must be a problem somewhere else in your code. I'm sorry, but I cannot help any further based on the example code you've posted.