Jump to content

Change level in Phaser 3


gamef1
 Share

Recommended Posts

Hi All,

this is my first post in the forum I searched for something similar to my issue, but I could not find it. I am making my first game, so I am doing some beginner mistake.

 

I have the level loaded as [Level0, Level1] Both are classes

class Level0 extends Phaser.Scene {

// all class code here

}

Then when the user hits space bar I want to load the Level1 (which is where the game begins).

 

const { cursors } = this;
   
    if (cursors.space.isDown && typeof window !== undefined) {
      window.game.scene.remove('Level0');
      window.game.scene.start('Level1');
    }

The problem is that while I am able to switch to the Level1, I can see that in fact the actual working scene is still the Level0. The music and images from Level 0 are not removed. 

The basic idea is Level0 is the start of the game, and hitting space bar you load the first Level, which is another class with its own music and images. 

I am loading the file correctly, what am I doing wrong?

    <script src="Scene0.js"></script>
    <script src="Scene1.js"></script>
    <script src="game.js"></script>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...