Jump to content

How to make buttons disable game.input.touch.*Callback?


tametick
 Share

Recommended Posts

Hi,

I have a game where I'm listening on touch/mouse events:

 

game.input.mouse.mouseDownCallback= onTouchStart;
game.input.mouse.mouseMoveCallback = onTouchMove;
game.input.mouse.mouseUpCallback = onTouchEnd;
game.input.touch.touchStartCallback = onTouchStart;
game.input.touch.touchMoveCallback = onTouchMove;
game.input.touch.touchEndCallback = onTouchEnd;
 
However I also want some buttons (e.g. back to menu, muting sounds/music, etc) to be above the game, and when these buttons are clicked to not respond to input event in the game. Right now I can work around it by adding a check in onTouchStart if game.input.activePointer is within the buttons' rect, but is there a better solution?
Link to comment
Share on other sites

That would only work if his buttons are DOM elements sitting over the top of the game.

 

What you can do is use priority IDs - for example if you had 2 sprites that overlapped, both of which had input handlers, if you gave the one on the top a higher priority ID then the one on the bottom would never fire. This is how I overlay buttons in my games and not have them all fire off at once!

Link to comment
Share on other sites

Nevermind, solved it by moving the event handlers to a 1x1 pixel sprite with scale set to fit the screen & then using priorityIds:

 

var bg = game.add.sprite(0, 0, 'bg');bg.fixedToCamera = true;bg.scale.setTo(origWidth, origHeight);bg.inputEnabled = true;bg.input.priorityID = 0;bg.events.onInputDown.add(onTouchStart,this);bg.events.onInputOver.add(onTouchMove,this);bg.events.onInputUp.add(onTouchEnd,this);
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...