Рендеринг в cocos2d -x с использованием значений математической функции

Доброе утро.

Я на 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);

В качестве альтернативы я пробовал:

   
    // 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 нужно больше времени для выполнения? Как я мог вычислить математического патрона, чтобы мои спрайты двигались за ним?

9
задан mram888 30 October 2012 в 23:30
поделиться