Jump to content

Swipe to Jump


rumdumdum
 Share

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;      player.animations.play('right');    }    if (Math.floor(game.input.x/(game.width/2)) === RIGHT) {      //  Move to the right      player.body.velocity.x = -150;      player.animations.play('left');    }    }

How can I record swiping up?

 

Cheers

Richard

Link to comment
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!

Link to comment
Share on other sites

  • 8 months later...

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);      
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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