2014-08-30 75 views
0

我試着在我的精靈的更新方法中做RotateBy。它只是翻譯。而不是旋轉。任何人都可以請告訴我該怎麼做?謝謝。如何同時旋轉和翻譯我的精靈? cocos2dx 3.2

void CBall::Update(float dt) 
{ 
    this->Start(); 
    auto action = RotateBy::create(dt,10); 
    this->runAction(action); 
} 

void CBall::Start() 
{ 


    float currentX = getPositionX(); 
    float distance = currentX + xOffset; 
    float time = distance/_speedX; 



    Vec2 destination = Vec2(distance,this->getPositionY()); 
    auto actionMove = MoveTo::create(time,destination); 
    this->runAction(actionMove); 

    if(currentX > _screenWidth) 
    { 
     ReachedEndOfScreen(); 
    } 


} 
+0

發佈您的代碼開始()成員函數... – LearnCocos2D 2014-08-30 19:46:02

回答

1

其實你需要使用Spawn action它會同時運行許多操作。

這裏是一個修改後的更新功能:

void CBall::Update(float dt) 
{ 

    float currentX = getPositionX(); 
    float distance = currentX + xOffset; 
    float time = distance/_speedX; 



    Vec2 destination = Vec2(distance,this->getPositionY()); 
    auto actionMove = MoveTo::create(time,destination); 

    if(currentX > _screenWidth) 
    { 
     ReachedEndOfScreen(); 
    } 
    auto actionRotate = RotateBy::create(dt,10); 
    this->runAction(Spawn::create(actionMove, actionRotate, nullptr)); 
} 

我內聯,你可以考慮重新組織更新實施一個由功能;-)

+0

非常感謝!實際上,我打算在這兩種方法中增加更多的東西,因此也就是單獨的方法。但無論如何,非常感謝你。這正是我所期待的。 – 2014-09-01 15:16:06

0

而不是在更新方法中應用其他操作,請嘗試應用第一個操作。同時增加角度並減少RotateBy動作的持續時間以進行測試。

float currentX = getPositionX(); 
float distance = currentX + xOffset; 
float time = distance/_speedX; 
Vec2 destination = Vec2(distance,this->getPositionY()); 

auto actionMove = MoveTo::create(time,destination); 
this->runAction(actionMove); 

auto action = RotateBy::create(4,720); 
this->runAction(action); 

我希望它有幫助。

+0

它仍然不適合我。我認爲這兩個是原子的。你一個接着一個跑。直觀地,即使序列也會這樣做。我想交錯兩個動作。請告訴我該怎麼做。 – 2014-08-31 07:19:26

+0

感謝您的迴應。 – 2014-08-31 07:19:43

+0

我很遺憾聽到這個消息。但是,我在cocos2d-x 3.1 – mohakagr 2014-08-31 14:09:13