Akrone 0 Posted February 17, 2017 Report Share Posted February 17, 2017 Hi, I'm currently learning Phaser, and i need to handle key events, so i saw some tutorials and if i want to move my character, i need to know if key is down so, in the "phaser" way, things are done like this: window.checkInputs = () => { let key = Phaser.Keyboard if ( game.input.keyboard.isDown(key.LEFT) ) { console.log('Left is down !') } } And i need to call this method in the update loop, so 60 times / s, phaser will check if left arrow is down, like i come from node.js, i don't like this, i mean it waste resources no ? So, is this methode better ? : window.addInput = () => { document.onkeydown = (e) => { if (e.code == 'ArrowLeft') { console.log('Left is down !') } } } Thanks ! Quote Link to post Share on other sites
mwissink 6 Posted February 17, 2017 Report Share Posted February 17, 2017 I would recommend checking out the Phaser's keyboard class. https://www.phaser.io/docs/2.6.2/Phaser.Keyboard.html It handles keyboard events and gives you access to other useful functions as well. Good Luck! Quote Link to post Share on other sites
samme 722 Posted February 17, 2017 Report Share Posted February 17, 2017 Phaser has both. For continuous input, it's more efficient and accurate to test the key directly. For infrequent events, you can bind to Phaser.Key.html#onDown. There's no need to add your own DOM handlers. Quote Link to post Share on other sites
Recommended Posts
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.