gpt4 book ai didi

android - 使用数学函数的值在 cocos2d-x 中渲染

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:38:51 25 4
gpt4 key购买 nike

早上好。

我在 linux 上,为 Android 使用 cocos2d-x。

我创建了一个计算圆值的函数。

        // Circle point updateCircle()    // x = number of iteration · SamplingPeriod   |-|-|-|    // y = A · sine ( 2 · PI · number of iteration · SamplingPeriod / Period )    int iterations = this->getNumberOfIterations();    CCPoint centerPoint = this->getCenter();    float x = centerPoint.x + this->getAmplitude() * cos( 2 * M_PI * iterations * this->getSamplingPeriod() * this->getFrequency() );    float y = centerPoint.y + this->getAmplitude() * sin( 2 * M_PI * iterations * this->getSamplingPeriod() * this->getFrequency() );    _newPoint = ccp( x, y );        // Create Array Actions    CCArray *myActionsArray = new CCArray(3);    // Set action move    CCAction *actionMove1 = CCMoveTo::create(this->getSamplingPeriod(), newPoint);                         // Move to next point        CCAction *actionMove2 = CCCallFuncN::create(this, callfuncN_selector(GameObject::updateCircle));       // call again this function        // Insert Objects    myActionsArray->insertObject(actionMove1, 0);    myActionsArray->insertObject(actionMove2, 1);    // Create Sequence    CCAction *action = CCSequence::create(myActionsArray);        // Set Tags    action->setTag(kActionMove);    // Run    this->runAction(action);    // Set new call to put new point in SamplingFrequency ms    iterations += 1;    static const int maxIterationCycle = 1 / (this->getSamplingPeriod() * this->getFrequency());    if (iterations >= maxIterationCycle)    {        iterations = 1;    }    this->setNumberOfIterations(iterations);    CCLog("texttx Iterations %d/%d", iterations, maxIterationCycle);

或者,我试过:

       // Set action move     CCAction *actionMove1 = CCCallFuncN::create(this, callfuncN_selector(GameObject::macroSetNewPoint));    CCAction *actionMove2 = CCDelayTime::create(this->getSamplingPeriod());    CCAction *actionMove3 = CCCallFuncN::create(this, callfuncN_selector(GameObject::updateCircle));

        // Set action move    CCAction *actionMove1 = CCMoveTo::create(this->getSamplingPeriod(), _newPoint);    CCAction *actionMove2 = CCDelayTime::create(this->getSamplingPeriod());    CCAction *actionMove3 = CCCallFuncN::create(this, callfuncN_selector(GameObject::updateCircle));

问题是我的游戏对象在圆圈中移动,但在大约 1000 次迭代后,它消失了,并在几秒钟后再次出现。我不知道发生了什么- 分数计算正确(我认为)

也许 moveto 需要更多时间来执行?我如何计算一个数学赞助人来移动我的 Sprite 跟随它?

最佳答案

我已经测试了您的代码并且工作正常。请检查您是否正在从另一个回调或其他东西更新点。如果数据是公开的,它可以由代码的另一部分更新。

关于android - 使用数学函数的值在 cocos2d-x 中渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11598283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com