ShadowMoon Posted February 27, 2018 Share Posted February 27, 2018 Are there any good examples or tutorials for swipes and touch/ tap events for Phaser 3. I am new to game development. I did this tutorial for phaser 3, played around with it, added sounds and such. But the next thing I wanted to do was try and port it to Android. I was able to get most of the look right, but for the life I me I can't figure out how to get the 'dude' to move!!! Any help would be appreciated. Thanks Link to comment Share on other sites More sharing options...
AdamRyanGameDev Posted February 28, 2018 Share Posted February 28, 2018 Check out this video from gamesfromscratch ShadowMoon 1 Link to comment Share on other sites More sharing options...
ShadowMoon Posted February 28, 2018 Author Share Posted February 28, 2018 Thanks for the video! He covers a lot on keystrokes and mouse input, but there still is nothing on mobile touch (taps / swipes). I am able to use hammer.js to detect swipes, but incorporating it into the update function is where I'm getting stumped for now. I'm pretty sure there is a way to handle touch events with just Phaser 3 which would be ideal. Link to comment Share on other sites More sharing options...
samme Posted February 28, 2018 Share Posted February 28, 2018 http://labs.phaser.io/index.html?dir=input/pointer/ ShadowMoon 1 Link to comment Share on other sites More sharing options...
ShadowMoon Posted February 28, 2018 Author Share Posted February 28, 2018 Hey samme, thanks! I was kind of looking at these. And this snippet will move the dude one little frame at a time: this.input.on('pointerdown', function(){ player.setVelocityX(-160); player.anims.play('left', true); }, this); but how can I get the update function to check if pointer is down, similar to what I'm able to do with the cursor keys? This is the example from the tutorial and it makes the dude run left. if (cursors.left.isDown) { player.setVelocityX(-160); player.anims.play('left', true); } Link to comment Share on other sites More sharing options...
AdamRyanGameDev Posted February 28, 2018 Share Posted February 28, 2018 Also check out this blog who has made a phaser3 mobile game http://browsergameshub.com/phaser3-lessons-and-code-pt1/ ShadowMoon 1 Link to comment Share on other sites More sharing options...
ShadowMoon Posted February 28, 2018 Author Share Posted February 28, 2018 Got it! Thanks everyone. I just made a variable moveLeft, set it to false. Then on the pressdown event changed it to true and have the if statement in update check the state. On tap, he hauls ass to the left Now the easy part of getting him moving left, right, and jumping. var moveLeft = false; function create(){ this.input.on('pointerdown', function(){ moveLeft = true; }, this); } function update(){ if (moveLeft) { player.setVelocityX(-160); player.anims.play('left', true); } } AdamRyanGameDev and PappasBiology 2 Link to comment Share on other sites More sharing options...
Recommended Posts