Akrone Posted February 17, 2017 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 ! Link to comment Share on other sites More sharing options...
mwissink Posted February 17, 2017 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! Link to comment Share on other sites More sharing options...
samme Posted February 17, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts