Phaser 场景的启动与切换

来源:互联网 发布:淘宝展现词怎么刷 编辑:程序博客网 时间:2024/06/05 09:21
/** * Created by Releed on 2017/4/25. */var game = new Phaser.Game(800,600,Phaser.CANVAS,'gameStage');game.MyState = {};var upKey;game.MyState.Startstate = {    preload:function () {        console.log('场景 1 preload');        game.load.image('pic','image/ra_einstein.png');//欲添加图片    },    create:function () {        console.log('场景 1 create');        game.add.sprite(0,0,'pic');//场景添加图片        upKey = game.input.keyboard.addKey(Phaser.Keyboard.A);//创建键盘监听    },    update:function () {        //console.log('update01');        if (upKey.isDown){  //判断按键是否按下            //game.state.start('upup');            game.state.start('state2'); //场景跳转----            /*            start (key, clearWorld, clearCache)            1.场景key   2.是否清除前场景数据(默认true-false则继承前场景数据)  3.是否清除cache(默认false            */        }    }};//-----------每一个场景都是相互独立的game.MyState.state2 = {    preload:function () {        console.log('场景 2 preload');    },    create:function () {        console.log('场景 2 create');        game.add.sprite(0,0,'pic');        /*也可以在前场景加载资源,到后续场景显示图片            这也就代表在刚执行游戏时将所有游戏资源加载完毕,后续场景单独调用        * */    },    update:function () {        console.log('场景 2 update');    }};//游戏内的每个场景都要添加game.state.add('Startstate',game.MyState.Startstate);game.state.add('state2',game.MyState.state2);game.state.start('Startstate');//启动场景//game.state.start('state2');//一般都启动一个场景
0 0
原创粉丝点击