tametick Posted December 19, 2013 Share Posted December 19, 2013 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 More sharing options...
XekeDeath Posted December 19, 2013 Share Posted December 19, 2013 Instead of adding the events to the game.input, create a screen sized invisible sprite under the buttons and attach the events to that instead?The events should stop at the buttons that way. Link to comment Share on other sites More sharing options...
powerfear Posted December 19, 2013 Share Posted December 19, 2013 I think if you use event.stopPropagation inside your buttons event handlers it should stop the touch event from reaching phaser event handler. Link to comment Share on other sites More sharing options...
XekeDeath Posted December 19, 2013 Share Posted December 19, 2013 I think if you use event.stopPropagation inside your buttons event handlers it should stop the touch event from reaching phaser event handler. I knew there was something like that. Go with this, it is a much better idea. Link to comment Share on other sites More sharing options...
rich Posted December 19, 2013 Share Posted December 19, 2013 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 More sharing options...
tametick Posted December 20, 2013 Author Share Posted December 20, 2013 Rich: what if the game itself has the input function? I can't seem to find its inputHandler to set the priorityIds. Link to comment Share on other sites More sharing options...
tametick Posted December 20, 2013 Author Share Posted December 20, 2013 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); patmood 1 Link to comment Share on other sites More sharing options...
Recommended Posts