Good morning.
I'm on linux, using cocos2d-x for Android
.
I have created a function that calculate circle values.
// 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, i have tried:
// 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));
And
// 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));
The problem is that my game object moves in circles, but after 1000 iterations approx, it dissapears, and appears again in a few seconds. I don't know what is going on - The points are correctly calculated (i think)
Maybe moveto needs more time to execute? How could I calculate a math patron to move my sprites following it?