MarrMooMoo 1 Report post Posted September 18, 2017 In my game I want my character to instantly move to predetermined points at the press of the left and right arrow keys. The player starts at x coordinate of 0. Here is my current code: var n = 0; cursors = game.input.keyboard.createCursorKeys(); var coordinates = [{x: 0}, {x: 100}, {x: 200}, {x: 300}, {x: 400}]; if (cursors.left.isDown && player.position.x != 0) { n -= 1; player.position.x = coordinates[n].x; } if (cursors.right.isDown && player.position.x != 400) { n += 1; player.position.x = coordinates[n].x; } So this basically works, but the problem is it runs it for however long I have the key pushed down, and I want it to only run once per key stroke. I read that onDown is what I'm looking for, but I'm not sure how to use that. Can someone help me out or suggest a better way? Quote Share this post Link to post Share on other sites
samid737 118 Report post Posted September 18, 2017 You can add the onDown input event in create to run once:https://codepen.io/Samid737/pen/aLdpqa 2 Jem Kazama and MarrMooMoo reacted to this Quote Share this post Link to post Share on other sites
MarrMooMoo 1 Report post Posted September 18, 2017 16 minutes ago, samid737 said: You can add the onDown input event in create to run once:https://codepen.io/Samid737/pen/aLdpqa You are a saint. Thanks! 1 samid737 reacted to this Quote Share this post Link to post Share on other sites