ゲームサイクルを完成させる
MenuSceneからGameSceneへ遷移する
- 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"); } // 追記 -ここまで- - MenuSceneを選択する
- ヒエラルキーパネルでStartButtonを選択する
- 遷移のイベントを設定する
未ログインの時はGAME STARTをできないようにする
- 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"); } - LoginUI.ts の修正
LoginUI.ts
if (data.success) { if (this.menuManager) { this.menuManager.setLoggedIn(true); // 追記 this.menuManager.updateLoginStatus(data.userData.username); } }
まとめ
これでタイトル→メニュー→ゲーム→リザルト→メニュー…のサイクルが完成しました。