Question:
I’m new to phaser so I don’t know how to use it very well, but how do you reset a phaser scene?
function reset(){
// reset
}
function create(){
// stuff that needs to be reset
}
Question:
I’m new to phaser so I don’t know how to use it very well, but how do you reset a phaser scene?
function reset(){
// reset
}
function create(){
// stuff that needs to be reset
}
It’s simply this.scene.restart();
which will reset the current scene.
If you want to reset a scene from another scene use this.scene.restart('SceneKey');
You can see others functions in their documentation too: Phaser.Scenes.ScenePlugin - Phaser 3 API Documentation (beta)
I tried it but it just gives me this error:
Can you share your repl link?
Try to update your scene configuration to include a reset function
const config = {
type: Phaser.AUTO,
width: 500,
height: 500,
backgroundColor: '#000000',
scene: {
preload: preload,
create: create,
reset: reset #add this line here
}
};
After that you can bind the reset to your create function too, just add this line at the end (but inside the create function() )
document.getElementById('button').onclick = this.reset.bind(this);
And change the reset function since the key is not needed in this case
function reset() {
this.scene.restart();
}
See if this works, I’m following their documentation here
I tried it but I got this instead… Did I put the document.getElementById('button').onclick = this.reset.bind(this);
in the right place?
I’m not seeing the line document.getElementById('button').onclick = this.reset.bind(this);
anywhere in your script.js
Oops, I took it out and forgot about it.
This is the real error i’m getting:
Oh I forgot to declare it within the create
function
Inside the create function declare the restart like this:
this.reset = function() {
this.scene.restart();
}
document.getElementById('button').onclick = this.reset.bind(this);
}
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.