【发布时间】:2014-07-08 15:28:11
【问题描述】:
我是 cocos2dx 的新手。在下面的代码中,在_nextProjectile->runaction 之后执行的回调函数中将_nextProjectile 添加到“this”的子项中(因为“finish shoot”总是在“run action”之后打印)。但是,我在finishShoot() 中打印_nextProjectile 的位置,这与我在创建_nextProjectile 时设置的位置完全相同。
所以我的问题是_nextProjectile->runAction 什么时候实际执行?
谢谢。
{
_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;
}
【问题讨论】: