PHASER3 设置场景SCENE SLEEPING休眠和WAKE唤醒

A good way to set scene stop when hidden and run while visible again !

使用sleep和wake方法的好处:

1.可以彻底让scene场景彻底休眠
2.update function不会再运行
3.同时会暂停场景内的Timer事件

GameScene.js代码

// phaser version 3.15.0
// 监听是否当前场景不可见/最小化
        this.sys.game.events.on('hidden', function () {
            console.log('pause spawn bomb while hidden');
            console.log('gamescene is sleeping?', this.scene.isSleeping('GameScene'));
            console.groupEnd();
            game.scene.keys['GameScene'].sys.sleep();

        }, this);

// 回到当前场景
        this.sys.game.events.on('visible', function () {
            console.log('spawn bomb while visible');
            console.groupEnd();
            console.log('gamescene is wake again:', this.scene.isSleeping());
            game.scene.keys['GameScene'].sys.wake();
            this.createCheckNetWork();
        }, this);

更多游戏教程:www.iFIERO.com – 为游戏开发深感自豪

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值