Gabriel Slomka
Gabriel Slomka

Reputation: 1527

Click on something that's not a sprite

I'm tryng to handle a click event that does not clicked on a sprite.

My first aproach would be handling normal JS events:

class EditorListener {

   constructor(editor) {
       ...
       if(window) {
           window.addEventListener('click', this.onWindowClick.bind(this));
       }
   }

   onWindowClick(event) {
       if(event.target && event.target.tagName == 'CANVAS') {
           Events.fire(EventType.CLICK_NOWHERE);
       }
   }
}
...

The problem is that this is called when I click sprites.

The goal is to simply close a dialog when I click nowhere.

Upvotes: 0

Views: 60

Answers (1)

User 987
User 987

Reputation: 748

Tap anywhere and run the function:

game.input.onTap.add(onTap, this);

function onTap(pointer) 
{
}

Tap on these objects and run the function onDown

// enable input for some objects
yourObject1.inputEnabled = true;
yourObject2.inputEnabled = true;

yourObject1.events.onInputDown.add(onDown, this);
yourObject2.events.onInputDown.add(onDown, this);

function onDown(object, pointer) 
{
    // on down function
}

Upvotes: 1

Related Questions