Mangoo

Keyboard event fired across multiple scenes, but shouldn't

Recommended Posts

Hi, 

i have two scenes, in Scene1 the player can input his name and if ENTER is press the second scene should start. Everything works fine so far, but when i make new keyboard input in the second scene the input events from scene 1 are also fired. 

  

scene 1 (from a lab example):

...
  create(){
    var self = this;
    this.add.text(10, 10, 'Enter your name:', { font: '32px Courier', fill: '#ffffff' });

    this.textEntry = this.add.text(10, 50, 'm', { font: '32px Courier', fill: '#ffff00' });
    this.text = "";
    this.input.keyboard.on('keydown',this.write,self);
  }

write(event){
      console.log("Key down in Scene 1");
      if (event.keyCode === 8 && this.textEntry.text.length > 0)
      {
          this.textEntry.text = this.textEntry.text.substr(0, this.textEntry.text.length - 1);
      }
      else if (event.keyCode === 32 || (event.keyCode >= 48 && event.keyCode < 90))
      {
          this.text +=event.key;
      }else if(event.keyCode === 13){
        this.scene.start("PlayGame",{name:this.textEntry.text});
      }
  }
...

scene 2:

...
create(){
    this.input.keyboard.on('keydown', function (event) {
      console.log("Key down in Scene 2");
        if (event.keyCode === 87)
        {
          console.log("Key W was pressed");
        }
    });
}
....

 

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.