2012-07-22 18 views
9

सुप्रभात से मूल्यों का उपयोग करके cocos2d-x में प्रस्तुत करना।गणित फ़ंक्शन

मैं Android के लिए cocos2d-x का उपयोग करके लिनक्स पर हूं।

मैंने एक ऐसा फ़ंक्शन बनाया है जो सर्कल मानों की गणना करता है।

 
     // 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 को निष्पादित करने के लिए और अधिक समय चाहिए? मैं अपने sprites को इसके बाद स्थानांतरित करने के लिए गणित संरक्षक की गणना कैसे कर सकता हूं?

उत्तर

5

मैंने आपके कोड का परीक्षण किया है और ठीक काम किया है। कृपया जांचें कि क्या आप किसी अन्य कॉलबैक या किसी चीज़ से कोई बिंदु अपडेट कर रहे हैं या नहीं। यदि डेटा सार्वजनिक है, तो इसे कोड के दूसरे भाग द्वारा अपडेट किया जा सकता है।