2012-07-22 2 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)); 

문제를 약 1,000 반복, 그것은 사라져, 이후 내 게임 객체 서클 이동하지만,이 나타나는 것입니다 다시 몇 초 후에 무슨 일이 일어나고 있는지 모르겠다. - 포인트가 올바르게 계산 된 것 같습니다. (제 생각 엔)

moveto가 더 많은 시간을 실행해야합니까? 수학 수호자가 그것을 따르는 스프라이트를 어떻게 계산할 수 있습니까?

답변

5

나는 귀하의 코드를 테스트 한 결과 괜찮습니다. 다른 콜백 또는 다른 지점에서 포인트를 업데이트하는지 확인하십시오. 공개 된 데이터는 코드의 다른 부분에 의해 업데이트되었을 수 있습니다.

관련 문제