shahbazk30 Posted March 10, 2014 Share Posted March 10, 2014 Hi All, Is there any built-in method to register swipe(right,left) event for sprite in PIXI.js. There is no such method listed in PIXI.js documentation (http://www.goodboydigital.com/pixijs/docs/classes/Sprite.html) or am i missing something? if there is no built-in method to register swipe event, Can i use "Sprite.touchend" event and write some logic to find swipe left and swipe write event. I have tried this approach by using "mouseData.getLocalPosition(mySprite)" but could not figure out how to find swipe( left and right). I am a newbie in Javascript any code snippet will be really helpful. Thanks shahbazk30 1 Quote Link to comment Share on other sites More sharing options...
xerver Posted March 10, 2014 Share Posted March 10, 2014 Related: https://github.com/GoodBoyDigital/pixi.js/issues/528 Quote Link to comment Share on other sites More sharing options...
shahbazk30 Posted March 11, 2014 Author Share Posted March 11, 2014 Hi All, For swap, I have experimented with sprite touch events and found following logic works for me. var initialPoint; var finalPoint; bunny.touchstart = function (interactionData) { initialPoint = interactionData.getLocalPosition(this.parent); } bunny.touchend = bunny.touchendoutside = function (interactionData) { finalPoint = interactionData.getLocalPosition(this.parent); var xAbs = Math.abs(initialPoint.x - finalPoint.x); var yAbs = Math.abs(initialPoint.y - finalPoint.y); if (xAbs > 20 || yAbs > 20) {//check if distance between two points is greater then 20 otherwise discard swap event if (xAbs > yAbs) { if (finalPoint.x < initialPoint.x) console.log("swap left"); else console.log("swap right"); } else { if (finalPoint.y < initialPoint.y) console.log("swap up"); else console.log("swap down"); } } } The code works fine, But please share your thoughts and let me know if I can improve above mentioned logic. Rex Rhino 1 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.