Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hey everybody, I wanted to ask how you guys deal with the circumstance that CC has this free-floating FPS camera after game start in the browser, until the user clicks the screen and the pointer is locked and hidden. This free-floating thing can be quite wild at times, and I have seen Unity users, doing the focus on the first keyhit (like WASD). The problem with pointer lock is, Javascript / html5 requires a user action to do so, for security reasons. User action may be mouse click, or key hit, or also giving focus to a new browser tab. The same is true for switching to fullscreen, and for playing a sound file. So I was wondering, whether anyone of you has some experience in switching to fullscreen due to user action, other than what the FPS camera does on the first mouse click. I already got this on keyhit "F": // ccbSwitchToFullscreen(true, 0, true); // does not work mycanvas=document.getElementById('3darea'); mypromise=mycanvas.requestFullscreen(); I think I could do the same with mypromise=mycanvas.requestPointerLock(); So I'd do that on any first user action, but only once. I guess I'll find out how CC likes that. But in any case, other opinions and experiences are welcome. |
||||
|
Alright, got it working, as soon as the user hits any key, I get pointerlock and fps camera: I'll try to post, but niko's spam-detector may panic... we'll see... [code] keyinit(); function keyinit() { mycanvas=document.getElementById('3darea'); mycanvas.a°d°d°E°v°e°n°t°L°i°s°t°e°n°e°r°('keydown', keymerk); mycanvas.setAttribute('tabindex','0'); mycanvas.focus(); } function keymerk(e) { // we ignore the key e, and after the pointerlock, unregister the event listener mycanvas=document.getElementById('3darea'); mycanvas.setAttribute('tabindex','0'); mycanvas.focus(); mypromise=mycanvas.requestPointerLock(); mycanvas.r°e°m°o°v°e°E°v°e°n°t°L°i°s°t°e°n°e°r('keydown', keymerk); } /code] This code is added to the "do something before first drawing" root scene behavior (execute javascript). Of course, remove the ° letters, they are just so the forum doesn't panic. |
||||
|
Thanks for the solution @dieter, as webGL and Android is the least explored areas of CC, it is a less likely to get a solution here, So Thanks a lot for sharing the solution. |
||||
|
Thanks, just_in_case I always enjoy sharing my experiences, and to read the reactions to it. |
|