早上好。
我在 linux 上,使用 cocos2d-x 进行Android.
我创建了一个计算圆值的函数。
// 圆点 updateCircle()
// x = 迭代次数 · SamplingPeriod |-|-|-|
// y = A · sine (2 · PI · 迭代次数 · SamplingPeriod / Period )
int 迭代 = this->getNumberOfIterations();
CCPoint centerPoint = this->getCenter();
float x = centerPoint.x + this->getAmplitude() * cos( 2 * M_PI * 迭代次数 * this->getSamplingPeriod() * this->getFrequency() );
float y = centerPoint.y + this->getAmplitude() * sin( 2 * M_PI * 迭代 * 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);
// 设置标签
动作->setTag(kActionMove);
// 跑
this->runAction(动作);
// 设置新调用以在 SamplingFrequency ms 中放置新点
迭代 += 1;
静态常量 int maxIterationCycle = 1 / (this->getSamplingPeriod() * this->getFrequency());
如果(迭代次数 >= maxIterationCycle)
{
迭代 = 1;
}
this->setNumberOfIterations(迭代);
CCLog("texttx 迭代次数 %d/%d", 迭代次数, 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 需要更多时间来执行?我如何计算一个数学赞助人来移动我的精灵跟随它?