Phaser JS how to stop the Distribution (dismissal) event from the textButton.events.onInputDown file on the game.input.onDown event?

Here is the JSFiddle .

I have two events here.

  • game.input.onDownwhich executes some logic (generates particles in my example)
  • textButton.events.onInputDownwhere textButton is a Phaser.Text instance of the object, which makes different logic.

The problem is this: when I click on textButton , both events fire 1 and 2 .

The question is how to prevent event 1 from firing when I click on textButton ?

Code Part:

...
//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);
...
+4
1

- - input.priorityID.

priorityID , . , , , , . priorityID. , .

: http://docs.phaser.io/InputHandler.js.html#sunlight-1-line-45

// This is event #1 added to background sprite
var bg = game.add.sprite(0, 0);
bg.fixedToCamera = true;
bg.scale.setTo(game.width, game.height);
bg.inputEnabled = true;
bg.input.priorityID = 0; // lower priority
bg.events.onInputDown.add(particleBurst);

, textButton :

textButton.input.priorityID = 1; // higher pirority

( ) :

function particleBurst(bg, pointer) {

.

: http://jsfiddle.net/g05bbL6g/3/

+5

Source: https://habr.com/ru/post/1568999/


All Articles