Jump to content

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

Recommended Posts


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 post
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...