Jump to content

Pixi.js swipe event


shahbazk30
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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