【问题标题】:What's code sequence in the below cocos2dx code?下面 cocos2dx 代码中的代码顺序是什么?
【发布时间】: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;
}

【问题讨论】:

    标签: cocos2d-x cocos2d-x-3.0


    【解决方案1】:

    两个动作同时运行。播放器在调用回调之前旋转了rotateDuration,同时nextprojectile(如果不是null)已经开始移动了。

    您似乎想在 finishShoot 方法中移动 nextprojectile 运行动作。

    【讨论】:

    • 不,实际上 nextProjectile 在旋转后开始移动。似乎 _nextProjectile 在添加到“this”后才开始移动
    • 当然,当它既不可见也不属于节点层次结构时,为什么它会移动呢?如果您需要它不可见地移动,请添加它并将其可见标志设置为 false。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-30
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多