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?

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

0
Posted at

ゲームサイクルを完成させる

MenuSceneからGameSceneへ遷移する

  1. MenuManager.tsに遷移処理を追加する
    MenuManager.ts
    import { _decorator, Component, Node, Label, director } from 'cc'; // directorを追加
    
    // ...
    public updateLoginStatus(username: string) {
        if (this.loginUserLabel) {
            this.loginUserLabel.string = `ユーザー名: ${username}`;
        }
    }
    
    // 追記 -ここから-
    public goToGame() {
        console.log("GameSceneへ移動します...");
        director.loadScene("GameScene");
    }
    // 追記 -ここまで- 
    
  2. MenuSceneを選択する
  3. ヒエラルキーパネルでStartButtonを選択する
  4. 遷移のイベントを設定する
    image.png

未ログインの時はGAME STARTをできないようにする

  1. MenuManager.tsに追記する
    MenuManager.ts
    @property(Label)
    loginUserLabel: Label = null;
    
    // 追記 -ここから-
    private isLoggedIn: boolean = false;
    public setLoggedIn(value: boolean) {
        this.isLoggedIn = value;
    }
    // 追記 -ここまで-
    
    // ...
    public goToGame() {
        if (!this.isLoggedIn) {
            alert("ログインしてから開始してください");
            
           
            this.openAuthPopup();
            return;
        }
    
        console.log("GameSceneへ移動します...");
        director.loadScene("GameScene");
    }
    
    ※今回は実験的にブラウザの標準アラートを活用します
  2. LoginUI.ts の修正
    LoginUI.ts
    if (data.success) {
        if (this.menuManager) {
            this.menuManager.setLoggedIn(true); // 追記
            this.menuManager.updateLoginStatus(data.userData.username);
        }
    }
    

まとめ

これでタイトル→メニュー→ゲーム→リザルト→メニュー…のサイクルが完成しました。

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?