2012-07-22 19 views
9

Guten Morgen.Rendern in cocos2d-x mit Werten aus einer mathematischen Funktion

Ich bin auf Linux, mit cocos2d-x für Android.

Ich habe eine Funktion erstellt, die Kreiswerte berechnet.

 
     // 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, ich habe versucht:

 
    // 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)); 

Und

 
     // 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)); 

Das Problem ist, dass mein Spiel Objekt bewegt sich in Kreisen, aber nach 1000 Iterationen ca., es verschwindet und erscheint wieder in ein paar Sekunden. Ich weiß nicht, was los ist - Die Punkte sind korrekt berechnet (ich denke)

Vielleicht braucht moveto mehr Zeit für die Ausführung? Wie könnte ich einen Mathe-Benutzer berechnen, um meine Sprites danach zu bewegen?

Antwort

5

Ich habe Ihren Code getestet und arbeite ok. Bitte überprüfen Sie, ob Sie einen Punkt von einem anderen Rückruf oder etwas aktualisieren. Wenn Daten öffentlich sind, könnten sie durch einen anderen Teil des Codes aktualisiert werden.

Verwandte Themen