Jump to content

Multiple keydowns simultaneously


szabo_sandor_istvan
 Share

Recommended Posts

Hi all,

I'm struggling understanding and debugging a weird behavior with multiple keydowns.

Let's suppose I want to build a 2d game in which you control an aircraft with Left/Right/Up/Down keys, and in the meantime fire with Space bar.

For debugging purposes I made a simple script that maps these keys to a text field of 5 digits (every digit matches a key, 0 when isDown event of the key is not fired, 1 when it is on).

The problem is when I hit Up+Right+Space, it doesn't trigger space.

On another computer (same Chrome, Windows 10 installation) it recognizes only Up+Right+Space, but not the other triplets (for ex. Up+Left+Space).

I think of an event limitation here in the this.input.keyboard.createCursorKeys object, or the Update event triggers so fast that the cursor event can't be fully tested.

Can you share your idea?

var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    backgroundColor: '#0072bc',
    width: 800,
    height: 600,
    dom: {
        createContainer: true
    },
   physics: {
        default: 'arcade',
        arcade: {
            debug: true
        }
    },
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

var cursors;
var scoreText;

var game = new Phaser.Game(config);

function preload ()
{
}

function create ()
{
    cursors = this.input.keyboard.createCursorKeys();

    scoreText = this.add.text(30, 50, '00000', { fontSize: '32px', fill: '#000000' }).setScrollFactor(0);
}

function update ()
{
    text = '';
    if (cursors.left.isDown)   text += '1'; else text += '0';
    if (cursors.right.isDown)  text += '1'; else text += '0';
    if (cursors.up.isDown)     text += '1'; else text += '0';
    if (cursors.down.isDown)   text += '1'; else text += '0';
    if (cursors.space.isDown)  text += '1'; else text += '0';
    scoreText.setText(text);
}
 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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