0
votes

I'm new to cocos2dx. In the below code, _nextProjectile is added to the children of "this" in the callback function which is executed after _nextProjectile->runaction (since "finish shoot" is always printed after "run action"). However, I print the position of _nextProjectile in finishShoot(), which is exact the same with that I set when I created the _nextProjectile.

So my question when does the _nextProjectile->runAction is executed actually?

Thank you.

{
    _player->runAction(Sequence::create(RotateTo::create(rotateDuration, cocosAngle), CallFuncN::create(CC_CALLBACK_0(HelloWorld::finishShoot, this)), NULL));

// Move projectile to actual endpoint
    printf("run action\n");
    _nextProjectile->runAction(Sequence::create(MoveTo::create(realMoveDuration, realDest), CallFuncN::create(CC_CALLBACK_1(HelloWorld::spriteMoveFinished, this)), NULL));
}

void HelloWorld::finishShoot()
{
    // Ok to add now - we've finished rotation!
    printf("finish shoot\n");
    this->addChild(_nextProjectile);
    // Add to projectiles vector
    _projectiles.pushBack(_nextProjectile);

    _nextProjectile = NULL;
}
1

1 Answers

1
votes

Both actions run simultaneously. The player rotates for rotateDuration before calling the callback, at the same time nextprojectile (if not null) already starts moving.

It seems like you may want to move the nextprojectile runaction in the finishShoot method instead.