SeanEBaby Posted April 12, 2014 Share Posted April 12, 2014 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 sharing options...
Pedro Alpera Posted April 12, 2014 Share Posted April 12, 2014 I have tried the example using a plain html and it works (os x chrome), I suppose you lost focus in the examples page because of the way the html it is made.Could you try this link? http://pedroalpera.com/phaser/playground/onkeydown_phaserexample/index.html Link to comment Share on other sites More sharing options...
SeanEBaby Posted April 12, 2014 Author Share Posted April 12, 2014 I have the bug using the example on chrome os x, try pushing 1, switching tab then back, then pushing 1 and it doesn't work... But the link you gave doesn't show the bug What did you change? Link to comment Share on other sites More sharing options...
Pedro Alpera Posted April 12, 2014 Share Posted April 12, 2014 Nothing, it is just a different html file, the javascript code is the same. It must be some other javascript file interfering on the phaser examples site, or perhaps the html file itself. I have attached the files to this post.onkeydown_phaserexample.zip Link to comment Share on other sites More sharing options...
SeanEBaby Posted April 13, 2014 Author Share Posted April 13, 2014 That hasn't solved the problem in my game, even when I copy those files you sent exactly.... ...but I did notice you are using v.2.0.2 and I (and the example page) are using 2.0.3 Link to comment Share on other sites More sharing options...
SeanEBaby Posted April 13, 2014 Author Share Posted April 13, 2014 I can confirm this bug is not in 2.0.2 but is in 2.0.3 How do we report this stuff? Link to comment Share on other sites More sharing options...
Pedro Alpera Posted April 13, 2014 Share Posted April 13, 2014 You are right, sorry, I thought I was using the last version, you can report it here: https://github.com/photonstorm/phaser/issues Link to comment Share on other sites More sharing options...
Pedro Alpera Posted April 13, 2014 Share Posted April 13, 2014 I have seen this, when you change tab and lost focus Phaser call this method: @method Phaser.Key#reset http://docs.phaser.io/Phaser.Key.html#reset Key.reset now clears any callbacks associated with the onDown and onUp events and nulls the onHoldCallback if set. Key.reset is called by Keyboard.reset when changing state. Link to comment Share on other sites More sharing options...
Heppell08 Posted April 13, 2014 Share Posted April 13, 2014 i tested this on chrome, had no issues at all. tabbed out and in multiple times to be sure. all working fine for me. Link to comment Share on other sites More sharing options...
SeanEBaby Posted April 13, 2014 Author Share Posted April 13, 2014 I have seen this, when you change tab and lost focus Phaser call this method: @method Phaser.Key#reset http://docs.phaser.io/Phaser.Key.html#reset Good spot, so I guess we have detect when focus comes back and setup the hotkey again? Link to comment Share on other sites More sharing options...
Pedro Alpera Posted April 13, 2014 Share Posted April 13, 2014 I think it could be a bug. Heppell08, have you tried this link? http://examples.phaser.io/_site/view_full.html?d=input&f=keyboard+hotkeys.js&t=keyboard%20hotkeys Link to comment Share on other sites More sharing options...
Pedro Alpera Posted April 15, 2014 Share Posted April 15, 2014 More information about this issue in this post: http://www.html5gamedevs.com/topic/5631-preserve-input-bindings/ 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() {}}; More info here: http://www.html5gamedevs.com/topic/3054-detect-when-the-game-change-visibility/?hl=onresume#entry19844 Link to comment Share on other sites More sharing options...
hbk619 Posted April 17, 2014 Share Posted April 17, 2014 The latest build fixed my issue with that but broke all my platforms collision objects. Hopefully that'll get sorted before the next release, unless there's something I have to change. Link to comment Share on other sites More sharing options...
SeanEBaby Posted April 18, 2014 Author Share Posted April 18, 2014 Thanks for all the help Pedro Link to comment Share on other sites More sharing options...
Heppell08 Posted April 18, 2014 Share Posted April 18, 2014 I think it could be a bug. Heppell08, have you tried this link? http://examples.phaser.io/_site/view_full.html?d=input&f=keyboard+hotkeys.js&t=keyboard%20hotkeysyeah it failed me on the site when i tabbed in and out. Link to comment Share on other sites More sharing options...
Recommended Posts