Wanderer777 Posted August 29, 2015 Share Posted August 29, 2015 Is there a short way to apply interactions to an object? Example -instead of:Button.on("mouseup", function(eventData) { titleScreen_Clear(); gameScreen_Create(); });Button.on("mouseout", function(eventData) { titleScreen_Clear(); gameScreen_Create(); });do something like this?Button.on(["mouseup","mouseout"], function(eventData) { titleScreen_Clear(); gameScreen_Create(); });or this?Button.on( "mouseup": myFunc, "mouseout": myFunc, ); Quote Link to comment Share on other sites More sharing options...
tips4design Posted August 29, 2015 Share Posted August 29, 2015 function doStuff() { titleScreen_Clear(); gameScreen_Create(); }Button.on("mouseup", doStuff);Button.on("mouseout", doStuff);This only applies in your case as both callbacks are indentical. I do not know any multiple bindings methods. Quote Link to comment Share on other sites More sharing options...
xerver Posted August 29, 2015 Share Posted August 29, 2015 You can't bind multiple events in a single "on" call right now. But .on() returns the object it is binding to, so:function doStuff() { titleScreen_Clear(); gameScreen_Create(); }Button.on("mouseup", doStuff).on("mouseout", doStuff); Quote Link to comment Share on other sites More sharing options...
Wanderer777 Posted August 30, 2015 Author Share Posted August 30, 2015 Button.on("mouseup", doStuff).on("mouseout", doStuff);This was what I was looking for - thanks! BTW - after adding touch support to my game and testing it on my Android tablet, I realized two problems: The entire game canvas gets highlighted with a blue rectangle each time the user taps on itTwo taps shortly after another are treated as a double-tap by the browser, which causes the browser to zoom the page Both are a real killjoy and very annoying while playing a game. How can this behaviour be suppressed? Quote Link to comment Share on other sites More sharing options...
GBeebe Posted August 30, 2015 Share Posted August 30, 2015 I don't know about the .on method. But methods like .onclick allow me to pass the event so I can event.preventDefault (); which stops the browser from doing stuff with the event. Quote Link to comment Share on other sites More sharing options...
Wanderer777 Posted August 30, 2015 Author Share Posted August 30, 2015 While I tried to test this this in various mobile browsers, I found that the touch events applied to PIXI objects do not work at all in Opera Mobile on Android. Quote Link to comment Share on other sites More sharing options...
xerver Posted August 30, 2015 Share Posted August 30, 2015 I don't know about the .on method. But methods like .onclick allow me to pass the event so I can event.preventDefault (); which stops the browser from doing stuff with the event. They are identical, just the .on() methods allow you to register multiple callbacks. You can do just what you said in the event handler registered using .on() as well. Quote Link to comment Share on other sites More sharing options...
Wanderer777 Posted August 31, 2015 Author Share Posted August 31, 2015 Pixi mobile support seems to be quite gappy Opera Mobile: Pixi touch actions do not work at all -but event.preventDefault() suppresses double-tap zooming.UC Mobile browser: Pixi touch actions do not work at all.Android standard browser: Pixi touch actions work, but there is still double-tap zooming. Quote Link to comment Share on other sites More sharing options...
xerver Posted August 31, 2015 Share Posted August 31, 2015 Pixi mobile support seems to be quite gappy Opera Mobile: Pixi touch actions do not work at all -but event.preventDefault() suppresses double-tap zooming.UC Mobile browser: Pixi touch actions do not work at all.Android standard browser: Pixi touch actions work, but there is still double-tap zooming. That doesn't really make sense, either interactions work or they don't. They can't "not work" but still get called so you can preventDefault... As far as wether or not preventDefault stops a browser action, that has nothing to do with pixi and everything to do with the browser and your user code. Quote Link to comment Share on other sites More sharing options...
Wanderer777 Posted August 31, 2015 Author Share Posted August 31, 2015 Sorry, to be more precise: - Opera Mobile: touch interactions within the game's canvas do not work at all. - UC Mobile: touch interactions within the game's canvas do not work at all. - Android browser: interactions with Pixi objects (buttons) do work, but double-tapping within the game canvas causes page zooming (even with event.preventDefault()). As far as I can see, event.preventDefault() just suppresses the blue overlay rectangle that was shown when touching the game canvas. Quote Link to comment Share on other sites More sharing options...
xerver Posted September 1, 2015 Share Posted September 1, 2015 Sorry, to be more precise: - Opera Mobile: touch interactions within the game's canvas do not work at all. - UC Mobile: touch interactions within the game's canvas do not work at all. - Android browser: interactions with Pixi objects (buttons) do work, but double-tapping within the game canvas causes page zooming (even with event.preventDefault()). As far as I can see, event.preventDefault() just suppresses the blue overlay rectangle that was shown when touching the game canvas. Hmm, not sure. I would open an issue and link it with this one: https://github.com/pixijs/pixi.js/issues/2071 Just another thing that should be fixed in the new interaction manager. Quote Link to comment Share on other sites More sharing options...
Exca Posted September 2, 2015 Share Posted September 2, 2015 Setting the viewport in html like:<meta name="viewport" content="width=device-width, user-scalable=no" />Should help with the zooming. Might not work on older androids though. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.