Sign in to follow this  

Swipe to Jump

Recommended Posts

Hello. I am looking to add a swipe action, so that I can make the player jump.


For navigation I have split the screen in two parts, if player clicks and holds on one right side the character will move right and vice versa.

if (game.input.pointer1.isDown){          if (Math.floor(game.input.x/(game.width/2)) === LEFT) {      //  Move to the left      player.body.velocity.x = 150;'right');    }    if (Math.floor(game.input.x/(game.width/2)) === RIGHT) {      //  Move to the right      player.body.velocity.x = -150;'left');    }    }

How can I record swiping up?




Share this post

Link to post
Share on other sites

Hey rumdumdum!


I implemented the swipe gesture in one of my prototypes lately.

See code below:

// 1st parameter determines the distance of the active pointer. My swipe distance trashhold is 150, you can play around with this value// in order to get a better feeling.// So basicly what you do is look for a certain distance (150) in a given time frame (min 100ms till 250ms).function onSwipe() {  return (Phaser.Point.distance(game.input.activePointer.position, game.input.activePointer.positionDown) > 150 && game.input.activePointer.duration > 100 && game.input.activePointer.duration < 250);}

Far from perfect, but it works fow now.

Hope this helps!

Share this post

Link to post
Share on other sites

Very basic but easy to understand and working on latest phaser


    var swipeCoordX,        swipeCoordY,        swipeCoordX2,        swipeCoordY2,        swipeMinDistance = 100;    game.input.onDown.add(function(pointer) {        swipeCoordX = pointer.clientX;        swipeCoordY = pointer.clientY;        }, this);    game.input.onUp.add(function(pointer) {        swipeCoordX2 = pointer.clientX;        swipeCoordY2 = pointer.clientY;        if(swipeCoordX2 < swipeCoordX - swipeMinDistance){            console.log("left");        }else if(swipeCoordX2 > swipeCoordX + swipeMinDistance){            console.log("right");        }else if(swipeCoordY2 < swipeCoordY - swipeMinDistance){            console.log("up");        }else if(swipeCoordY2 > swipeCoordY + swipeMinDistance){            console.log("down");        }    }, this);      

Share this post

Link to post
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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.