Jump to content

Handling cross-scene input for a sprite


AlanSmithee
 Share

Recommended Posts

Hi,

 

I am running two scenes in parallell.

 

I add a sprite in one scene, but I want to make it interactive in another scene, so that the code bellow would work

// In scene 2

this.input.on('pointerdown', (pointer, [gameObject]) => {
    if (!gameObject) {
        console.log('clicked', gameObject)
    }
})

 

I have tried to explicitly add it to scene 2

// in scene 2, "sprite" was created in scene 1 and passed via the data register
if (sprite) {
    sprite.setInteractive()
    this.add.existing(sprite)
}

 

But this does not work since even if `add.existing(...)` does add the sprite to the input list, it does so using `object.scene` which is the scene were the sprite was originally created.

 

Sp, my question is, can I add the external sprite to the scenes input list (without duplicating the data preferrably)?

 

Thanks in advance.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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