hi,
I 've made this simple jsfiddle to show my problem.
I know how remove a scene with :
scene.scene.remove('key')
But the problem is with the update function. If i kill my objects, the update function log me errors.
What’s the proper way to do that ?
Thanks in advance.
https://jsfiddle.net/espace3d/e7xdtv4m/48/
var obj;
const my_game = {
init: () => {
var main = new Phaser.Class({
Extends: Phaser.Scene,
initialize: function main() {
Phaser.Scene.call(this, {
key: 'main'
});
},
create: function () {
obj = {
x: 15
}
let _this = this
window.setInterval(function () {
_this.scene.remove("main")
_this.scene.start("main")
}, 2000);
},
update: function () {
if (obj.x > 10) {
// just to reveal the problem with state
//HERE THE ERROR
}
},
});
var config = {
type: Phaser.WEBGL,
width: 320,
height: 320,
backgroundColor: '#fffff',
parent: 'phaser-example',
physics: {
default: 'matter',
matter: {
debug: false,
gravity: {
y: 0,
x: 0,
}
},
},
scene: [main]
}
var game = new Phaser.Game(config);
},
}
my_game.init()