Jump to content

[2.0.3] Possible keyboard input bug


SeanEBaby
 Share

Recommended Posts

Firstly happy birthday phaser, started a project a few months ago and I'm loving working with the framework!

 

I've been trying to implement something using the game.input.keyboard.addKey methods and found some weird behaviour which can be recreated in the keyboard hotkeys example....

 

http://examples.phaser.io/_site/view_full.html?d=input&f=keyboard+hotkeys.js&t=keyboard%20hotkeys

 

Everything works great (windows 8.1 on chrome) until you focus on another window (or minimise and click the desktop) and come back to it, then the hotkeys don't work until you refresh the page.

 

Anyone else noticed this?  Is this a known issue?  Is it just something we are stuck with?

Link to comment
Share on other sites

More information about this issue in this post:
 
 
Finally it is not a bug, but there are some changes in the next update :)
 
Meanwhile a few solutions, you could use this:
 
game.stage.disableVisibilityChange = true;

 The game doesn't stop when you change tab.

Other solution would be what you propose, detect when focus comes back and setup the hotkey again:

window.onload = function () {    var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });    var block;function preload() {    game.load.image('phaser', 'assets/phaser-dude.png');    game.load.image('logo', 'assets/phaser_tiny.png');    game.load.image('pineapple', 'assets/pineapple.png');}var key1;var key2;var key3;function create() {    console.log("create");    this.game.onResume.add(yourGameResumedFunc, this)      game.stage.backgroundColor = '#736357';    game.add.text(0,0,'Press one, two or three !',{});    //  Here we create 3 hotkeys, keys 1-3 and bind them all to their own functions    key1 = game.input.keyboard.addKey(Phaser.Keyboard.ONE);    key1.onDown.add(addPhaserDude, this);    key2 = game.input.keyboard.addKey(Phaser.Keyboard.TWO);    key2.onDown.add(addPhaserLogo, this);    key3 = game.input.keyboard.addKey(Phaser.Keyboard.THREE);    key3.onDown.add(addPineapple, this);}function yourGameResumedFunc () {    key1.onDown.add(addPhaserDude, this);    key2.onDown.add(addPhaserLogo, this);    key3.onDown.add(addPineapple, this);}function addPhaserDude () {    game.add.sprite(game.world.randomX, game.world.randomY, 'phaser');}function addPhaserLogo () {    game.add.sprite(game.world.randomX, game.world.randomY, 'logo');}function addPineapple () {    game.add.sprite(game.world.randomX, game.world.randomY, 'pineapple');}function update() {}function render() {}};
 
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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