Jump to content

Changing Scene Issue


JavaNerd
 Share

Recommended Posts

In my game, when I change scenes from the main scene, to another, and then back to the main scene, it starts picking up additional input actions. For example, if I put console.log("") in:

			this.input.on('pointerup', function () {}, this);

it will print 4 times. Any idea on how to fix this or what is going on?

Link to comment
Share on other sites

Okay, so this is weird. I left my input listeners in my create function, but surrounded it with this

if(gameLoaded) { }

at the bottom of my create function, I put:

gameLoaded = true;

This prevented my input listeners from being repeated. But then my console.log went from 4 to 2 times per click. Then after each time of leaving the scene and coming back, it would go up by one. I then removed the gameLoaded check from around my input listeners and then added this code:

if(gameLoaded % 2)
{
        this.scene.restart();
}

and put it at the top of my create function. and put this at the bottom of my create function:

gameLoaded++;

with gameLoaded set to 1 initially.

Now my game works as intended, but this seems like a bit of a hacky workaround. Is there a better way to accomplish not repeating input listeners and changing scenes back and forth?

Link to comment
Share on other sites

17 hours ago, JavaNerd said:

But then my console.log went from 4 to 2 times per click. Then after each time of leaving the scene and coming back, it would go up by one.

Can you add one console.log at the start of your init or create function? I wonder if your scene is getting started twice somehow.

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...