A good way to set scene stop when hidden and run while visible again !this
使用sleep和wake方法的好處:spa
1.能夠完全讓scene場景完全休眠
2.update function不會再運行
3.同時會暫停場景內的Timer事件code
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 – 爲遊戲開發深感自豪遊戲