Stop POINTER_DOWN events after GAMEOBJECT_POINTER_DOWN event

Hello everyone,
I’m just getting into Phaser and I’m having some problems getting my click events to work. Here’s a simple code example.

export class TestScene extends Phaser.Scene {
    preload() {
    }
    create() {
        let g = this.add.zone(0,0,30,30).setInteractive();
        g.on(Phaser.Input.Events.GAMEOBJECT_POINTER_DOWN, function() {console.log('Game Object clicked'); this.input.stopPropagation()}, this);    
        this.input.on(Phaser.Input.Events.POINTER_DOWN, function() {console.log('Screen clicked');}, this);
    }
}

I would expect that after the GAMEOBJECT_POINTER_DOWN event was called it would stop the propagation and the POINTER_DOWN event would never fire, but they both are. What is the correct way to only have the higher up event handlers stop the propagation of events?

see in docs, call back is passes 4 arguments (pointer, localX, localY, event). You can call event.stopPropogation() to stop it from going up.

This would help too.

5 Likes

Thanks. That’s the piece that I was missing. I was trying to call the stopPropagation() on this.input and not on the event. I swear I’ve been looking at examples and reading documentation for an hour and not finding anything but it seems obvious now that you’ve pointed it out.

So this callback works like expected:

function(pointer, x, y, event) {console.log('Game Object clicked'); event.stopPropagation();}

2 Likes