Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listener's are constantly increasing. #6910

Open
jebarpg opened this issue Sep 26, 2024 · 1 comment
Open

Listener's are constantly increasing. #6910

jebarpg opened this issue Sep 26, 2024 · 1 comment

Comments

@jebarpg
Copy link

jebarpg commented Sep 26, 2024

listener increasing

Version

  • Phaser Version: "phaser": "3.85.1",
  • Operating system: Windows
  • Browser: Chrome

Description

I'm clicking a simple button and it keeps creating new Listeners and never getting rid of them.

here is the code I think is having the issue:


buttons: Array<Phaser.GameObjects.Image>;

constructor() {
    super('Shop');
    this.buttons = new Array<Phaser.GameObjects.Image>();
}

create() {

this.buttons.push(this.add.image(100, 100, 'my_button').setInteractive({ draggable: true }).addListener('pointerdown', () => { this.button_click_index = 0; console.log(this.button_click_index); }).addListener('drag', (
      _pointer: Phaser.Input.Pointer,
      _dragX: number,
      dragY: number) => {
      this.drag(_pointer,
        _dragX,
        dragY)
    }));
}

this.buttons.push(this.add.image(100, 200, 'my_button').setInteractive({ draggable: true }).addListener('pointerdown', () => { this.button_click_index = 0; console.log(this.button_click_index); }).addListener('drag', (
      _pointer: Phaser.Input.Pointer,
      _dragX: number,
      dragY: number) => {
      this.drag(_pointer,
        _dragX,
        dragY)
    }));
}

the drag function looks like this:

drag(_pointer: Phaser.Input.Pointer,
    _dragX: number,
    dragY: number) {
    for (let i = 0; i < this.buttons.length; i++) {
        this.buttons[i].setY(dragY + i * 200);
    }
  }

Listeners are increasing each time I click the image "button"

any idea's why the listeners would keep increasing and not stay static after the page screen load?

Additional Information

@photonstorm
Copy link
Collaborator

There's nothing in the shown code that would cause it, so it has to be something outside of this. Try re-creating it in a Phaser Sandbox. Boil it down to the bare essentials.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants