elgraniaco Posted May 15, 2014 Share Posted May 15, 2014 Hi,I was wondering if there's a built-in way to get the touch position the same way stage.getMousePosition() does with the mouse.I am using stage.getMousePosition() in my update function to get the mouse position constantly and I would need to mirror the behavior in mobile. Many thanks. Quote Link to comment Share on other sites More sharing options...
samim Posted May 29, 2014 Share Posted May 29, 2014 I ended up using this strategy:var currentMousePos = { x: -1, y: -1 };$(function () { document.addEventListener("touchstart", onTouchStart, true); document.addEventListener("touchend", onTouchEnd, true); document.addEventListener("touchmove", onTouchMove, true);}function onTouchStart(event){ currentMousePos.x = event.pageX; currentMousePos.y = event.pageY;}function onTouchMove(event){ currentMousePos.x = event.pageX; currentMousePos.y = event.pageY;}function onTouchEnd(event){ currentMousePos.x = event.pageX; currentMousePos.y = event.pageY;} Quote Link to comment Share on other sites More sharing options...
d13 Posted May 29, 2014 Share Posted May 29, 2014 Could you use `sprite.data.getLocalPosition(sprite.parent)` ? var pointer = sprite.data.getLocalPosition(sprite.parent);You then end up with `pointer.x` and `pointer.y` that tell you the position of either the mouse event, touch event, or both. It should work for any DisplayObject, not just sprites. Quote Link to comment Share on other sites More sharing options...
elgraniaco Posted June 3, 2014 Author Share Posted June 3, 2014 First of all, thank you very much for the replies.The approach to a solution I used is something in the lines of samim's, my question was whether PIXI had a built-in function like stage.getMousePosition() in order to simplify my code (I would only have to add one line of new code to my "on mouse hold" position catching logic). I've done my research though and found out there isn't. Again, thank you very much. 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.