Apathy Posted March 23, 2015 Share Posted March 23, 2015 I uploaded the game on fgl. The game gets put in a iframe. While in firefox it works fine, in Chrome it seems to have a problem. When the keys on keyboard get pressed, nothing happens in the game, instead it is the window that moves when pressing the up and down keys. I entered the following code game.system.canvas.focus(); and game.system.canvas.setAttribute('tabindex','0'); and somehow the keys now work for the game. But the keys still move the window as a whole. Is there a way to focus only the canvas? Quote Link to comment Share on other sites More sharing options...
enpu Posted March 23, 2015 Share Posted March 23, 2015 Try return true on your keydown function, that will call preventDefault on the key event. Quote Link to comment Share on other sites More sharing options...
andreialex Posted March 23, 2015 Share Posted March 23, 2015 Returning from an fired event does not always stops the propagation as the event will still continue on some browsers.What is the correct way to do is to event.preventDefault(); where you want to stop the event. Quote Link to comment Share on other sites More sharing options...
Apathy Posted March 23, 2015 Author Share Posted March 23, 2015 Thanks. Yeah returning true solved it! Thanks for the help both of you! Quote Link to comment Share on other sites More sharing options...
enpu Posted March 23, 2015 Share Posted March 23, 2015 @andreialex The engine will call event.preventDefault(); if you return true on keydown function:keydown: function(key) { // do something return true;} Quote Link to comment Share on other sites More sharing options...
andreialex Posted March 23, 2015 Share Posted March 23, 2015 True, documented better now. Quote Link to comment Share on other sites More sharing options...
Apathy Posted March 23, 2015 Author Share Posted March 23, 2015 There is still smth. I only saw it now! Though it is fixed when pressing a key, the window doesn't scroll, it is not the same when you keep the button up or down pressed for some time, which makes the window scroll again. Quote Link to comment Share on other sites More sharing options...
enpu Posted March 24, 2015 Share Posted March 24, 2015 You are right! This is now fixed on develop branch, though you should not update to it now.Quick fix would be to remove this line from keyborad.js:https://github.com/ekelokorpi/panda.js-engine/blob/master/src/engine/keyboard.js#L36 Quote Link to comment Share on other sites More sharing options...
Apathy Posted March 24, 2015 Author Share Posted March 24, 2015 Yes this fixed it! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.