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?

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

0
Posted at

タイトルシーンからメニューシーンへ遷移する

スクリプトを作成する

  1. Assetsパネルにscriptsフォルダを作る
  2. scriptsフォルダを右クリック→Create→TypeScriptを選択する
  3. AutoSceneTransition.tsにリネームする
  4. Visual Studio CodeでNewProject(Cocos Creatorのプロジェクトフォルダ)を開く
  5. 作成したAutoSceneTransition.tsを開く
  6. 下記をコピペする
    import { _decorator, Component, director } from 'cc';
    const { ccclass, property } = _decorator;
    
    @ccclass('AutoSceneTransition')
    export class AutoSceneTransition extends Component {
    
        @property({ type: Number })
        transitionDelay: number = 3;
    
        @property({ type: String })
        targetSceneName: string = 'MenuScene'; 
    
        start() {
            this.scheduleOnce(this.loadTargetScene, this.transitionDelay);
        }
    
        loadTargetScene() {
            if (this.targetSceneName) {
                director.loadScene(this.targetSceneName);
            } else {
                console.error('遷移先のシーン名が設定されていません。');
            }
        }
    }
    

作成したScriptをTitleSceneへ設定する

  1. Cocos CreatorでTitleSceneを選択する
  2. ヒエラルキーパネルのSceneRootノードにAutoSceneTransition.tsをドラッグ&ドロップする
  3. 画面上部のプレイボタンを押して実行する
  4. 3秒後にMenuSceneで設定したボタンが表示されたらOK
    image.png

まとめ

これでシーンの遷移が完了しました。

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?