How do you reset a phaser scene?

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)

1 Like

I tried it but it just gives me this error:Screenshot 2023-05-23 7.54.38 AM

Can you share your repl link?

1 Like


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() {

See if this works, I’m following their documentation here


Screenshot 2023-05-23 9.12.33 AM

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

1 Like

Oops, I took it out and forgot about it. :sweat_smile:
This is the real error i’m getting:
Screenshot 2023-05-23 9.23.20 AM

1 Like

Oh I forgot to declare it within the create function

Inside the create function declare the restart like this:

this.reset = function() {
    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.