早上好。
我在使用cocos2d-x开发Android
应用,系统是Linux。
我创建了一个计算圆值的函数。
// Circle point updateCircle() // x = 迭代次数 · 采样周期 |-|-|-| // y = A · 正弦 ( 2 · PI · 迭代次数 · 采样周期 / 周期 ) 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 );
// 创建动作数组 CCArray *myActionsArray = new CCArray(3);
// 设置移动动作 CCAction *actionMove1 = CCMoveTo::create(this->getSamplingPeriod(), newPoint); // 移动到下一个点 CCAction *actionMove2 = CCCallFuncN::create(this, callfuncN_selector(GameObject::updateCircle)); // 再次调用该函数
// 插入对象 myActionsArray->insertObject(actionMove1, 0); myActionsArray->insertObject(actionMove2, 1);
// 创建序列动作 CCAction *action = CCSequence::create(myActionsArray);
// 设置标签 action->setTag(kActionMove);
// 运行动作 this->runAction(action);
// 设置新的调用,在采样周期毫秒后放置新的点 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);
或者,我尝试了:
// 设置移动动作 CCAction *actionMove1 = CCCallFuncN::create(this, callfuncN_selector(GameObject::macroSetNewPoint)); CCAction *actionMove2 = CCDelayTime::create(this->getSamplingPeriod()); CCAction *actionMove3 = CCCallFuncN::create(this, callfuncN_selector(GameObject::updateCircle));
和
// 设置移动动作 CCAction *actionMove1 = CCMoveTo::create(this->getSamplingPeriod(), _newPoint); CCAction *actionMove2 = CCDelayTime::create(this->getSamplingPeriod()); CCAction *actionMove3 = CCCallFuncN::create(this, callfuncN_selector(GameObject::updateCircle));问题在于我的游戏对象会循环移动,但大约1000次迭代后,它会消失,几秒钟后又出现了。 我不知道发生了什么。 - 我认为点数计算是正确的。
也许moveto需要更多的执行时间? 如何计算一个数学模式来移动我的精灵并跟随它?