ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator WebGL FPS Camera initial focus
person icon
Dieter
Guest
Quote
2023-08-21 16:22:19

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.

person icon
Dieter
Guest
Quote
2023-08-21 17:11:07

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.

person icon
just_in_case
Moderator
Quote
2023-08-23 06:01:17

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.

person icon
Dieter
Guest
Quote
2023-08-23 12:30:54

Thanks, just_in_case
I always enjoy sharing my experiences, and to read the reactions to it.


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |