Here is the JSFiddle.
I have two events here.
- Is
game.input.onDown
which does some logic (generates particles in my example) - Is
textButton.events.onInputDown
, where textButton is a Phaser.Text object instance, which does another logic.
The problem is: when I click on my textButton both event are fired 1 and 2.
The question is, how to prevent event 1 from firing when I click on the textButton?
Part of code:
...
//This event is fired on click anywhere event # 1
game.input.onDown.add(particleBurst, this);
//This is Clickable text
textButton = game.add.text(game.world.width - 5, 5, "CLICK ME", fontStyle);
textButton.anchor.setTo(1, 0);
textButton.inputEnabled = true;
//This event is fired on click on text event # 2
textButton.events.onInputDown.add(function () {
console.log("button is Clicked");
}, this, 2);
...
You can add a background - transparent sprite - and use
input.priorityID
.See: http://docs.phaser.io/InputHandler.js.html#sunlight-1-line-45
Make sure your textButton has higher priority:
Add the clicked sprite (our background) as a first parameter to the particle function:
This way only one event should be triggered.
Check out modified fiddle: http://jsfiddle.net/g05bbL6g/3/