0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【17日目】25日間でCocos Creatorでゲームを作る

0
Posted at

リザルト画面を表示する

まずは遷移を作成するため、GameSceneに遷移後、2秒後にリザルトが表示されるようにします。
また、スコアについてもランダムで表示をします。

ResultPanelを非表示にする

  1. ヒエラルキーパネルでResultPanelを選択する
  2. インスペクターのResultPanelの横のチェックボックスを外す

GameManager.tsを修正する

  • start()メソッドにスコアの生成とリザルトの呼び出しを追加する
    start() {
        // 1. スコアを1〜1000の間でランダムに生成
        this.score = Math.floor(Math.random() * 1000) + 1;
        
        // 2. プレイ中のHUDに一旦表示(あれば)
        if (this.scoreLabel) {
            this.scoreLabel.string = `Score: ${this.score}`;
        }
    
        // 3. 2秒後にリザルトを表示する
        this.scheduleOnce(() => {
            this.finishGame();
        }, 2.0);
    }
    

動作確認をする

  1. GameSceneを起動する
  2. リザルト画面が表示されることを確認する
  3. 「もう一回」を選択する
  4. リザルト画面が表示されることを確認する
  5. 「メニュー」を選択する
  6. MenuSceneへ遷移する

まとめ

結果表示やボタンの挙動はこれで完成です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?