rumdumdum Posted February 15, 2014 Share Posted February 15, 2014 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? CheersRichard Link to comment Share on other sites More sharing options...
luschn Posted February 15, 2014 Share Posted February 15, 2014 I just started playing around with Phaser, so don´t know if there´s a good way with the engine directly. But what about using some library like "hammer.js" for the swipe stuff? Usually works great and is very easy to use. rumdumdum 1 Link to comment Share on other sites More sharing options...
imshag Posted February 15, 2014 Share Posted February 15, 2014 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! Teemu-Tor, r00 and rumdumdum 3 Link to comment Share on other sites More sharing options...
rumdumdum Posted February 15, 2014 Author Share Posted February 15, 2014 Thanks @luschn and @imshag I tested both options and using @imshag's suggested approach resulted in a smoother input experience with less jitter, but hammer.js is a great tool that will defiantly come in handy. Thanks again guys Link to comment Share on other sites More sharing options...
Heppell08 Posted February 19, 2014 Share Posted February 19, 2014 Is there a working version of this for phaser 1.1.5 for the swipe to jump?I got the left and right working but i keep getting undefined errors when trying the swipe to jump code... Thanks Link to comment Share on other sites More sharing options...
Sam Posted November 18, 2014 Share Posted November 18, 2014 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); markergreen 1 Link to comment Share on other sites More sharing options...
Recommended Posts