9
我在linux上,使用cocos2d-x为Android
。
我已经创建了一个计算圆圈值的函数。
// 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);
Alternativally,我曾尝试:
// 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需要更多的时间来执行? 我怎么能计算一个数学赞助人移动我的精灵之后?