splash27 Posted March 19, 2018 Share Posted March 19, 2018 I suppose that using document.addEventListener("keydown", function (event) { //detect key and instantly do something }); is not a good way, because it works outside the game loop. This might cause synchronization and performance issues in some cases. So far as I know, there are a keyboard event queue in most games. When user press button the corresponding event being placed into the queue. The the callback actually fired from game loop and queue reduces. Is there such mechanism in BabylonJS? How to attach my keyboard handling to it? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted March 19, 2018 Share Posted March 19, 2018 https://www.babylonjs-playground.com/#1MK1Y4#13 Hiya S... good to see you again. Would THAT method of keypress-checking (our ActionManager) smell any fresher? I haven't studied the underbelly of actionManager event-wrangling, but if I know Deltakosh and The Core Boys... they have done their best to smoooooothly integrate into browser event system. Them guys are HOT! I think... if you can use the ActionManager key-testing 'method', you'll be fartin' thru silk. (in good hands with good keypress listening). Now, I hope I was anywhat on-subject. As far as buffering-up held/fast keypress events... boy... let's BOTH ask for information about that. Those answers might be at browser, OS, or hardware levels. http://unixpapa.com/js/key.html Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted March 19, 2018 Share Posted March 19, 2018 ActionManager is a good solution, But, I'm not seeing any issues using eventListener like you did, internally, the actionManager also uses those ( all user-input does ) you could add it to the canvas element instead, so they are only fired while canvas has focus. If you want a 'queue', simply write one using an array , but i doubt it is necessary. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 19, 2018 Share Posted March 19, 2018 scene.onKeyboardObservable.add((e)=>{ console.log(e); }) Wingnut and inteja 2 Quote Link to comment Share on other sites More sharing options...
splash27 Posted March 20, 2018 Author Share Posted March 20, 2018 I wonder how many entry points for keyboard handling in BabylonJS: ActionManager, KeyboardObservable, camera's keys and checkInputs, default JS addEventListener. What is the best way to implement in-game controls (firing, reloading, gun switching etc.)? Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted March 20, 2018 Share Posted March 20, 2018 Observables Quote Link to comment Share on other sites More sharing options...
Guest Posted March 20, 2018 Share Posted March 20, 2018 As @Pryme8 mentioned, they are all connected through observables 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.