Jump to content

Keyboard multi-scene on parallel scenes


Deadowl
 Share

Recommended Posts

Hello,

I have two scenes that use this code, the one that launches by default, works fine, but when I launch the second scene

class BaseScene extends Phaser.Scene {
   ...
   create() {       
      this.keys = this.input.keyboard.createCursorKeys()
   }

   update() {

      if (this.keys.left.isDown) {
        // actions
      } else if (this.keys.right.isDown) {
        // actions
      } else if (this.keys.up.isDown) {
        // actions
      } else if (this.keys.down.isDown) {
        // actions
      } else {
        // actions
      }
   }
   ...
}
this.scene.setVisible(false)
this.scene.launch('sceneB', data )

I find that the keyboard events don't fire on the launched scene.

I need both scenes running in parallel, and the keyboard available on the current visible scene.  And the reason is that I need my npcs to keep moving over the "world" even when the player is not in their scenes,  ¿is there a better solution for my problem?.
Maybe a large map works better for me, I do not know, I'm new to the development of games.

Thank you in advance and sorry for my bad english, it is not my native language.

Problem solved

this.input.keyboard.enabled = false

let scene = this.scene.get('sceneB')
scene.input.keyboard.enabled = true

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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