2017-02-16 9 views

答えて

1

scheduleメソッドを使用すると、一定時間後に関数を呼び出して、それに応じてタイマーのラベルを更新できます。

これをチェックアウト:

  1. をプライベートintメンバーを作成は、例えばcountdownと呼ばれ、あなたからカウントダウンしたい秒数でそれを初期化します。また、あなたのシーンのinit方法では、タイマーのLabel(のはlblそれを呼びましょう)

  2. を宣言アップデータをスケジュールし、この

    this->lbl = Label::createWithTTF(std::to_string(this->countdown), "fonts/Marker Felt.ttf", charSize/15); // make sure you #include <string> 
    lbl->setPosition(Vec2(0,0));  // set the position to wherever you like 
    this->schedule(schedule_selector(MySceneClass::updateTimer), 1.0f); // calls updateTimer once every second 
    
  3. 宣言のようなラベルを初期化し、このような何かを見てupdateTimerを実装:

    void MySceneClass::updateTimer(float dt)  
    { 
        if (!countdown) 
         return;  // when countdown reaches 0, stop updating to avoid negative values 
        lbl->setString(std::to_string(--countdown)); 
    } 
    
関連する問題