Jump to content

Would it not be better to handle key events with listeners ?


Akrone
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...