Fullscreen/Windowed Toggle in Cocos Creator

Hi, is it possible to toggle “desktop windowed” mode and “mobile or fullscreen mode” in cocos creator. Example: if i were using an android browser i would like to see my app embebed in a web page. This i am able to do. What i not able to do yet is to change to fullscreen so i could see my app using all the screen resolution. Thanks and sorry for my bad english.

PD: what i am trying to do is what youtube does. Change from a embebed app to a fullscreen app just pressing a button. Thanks.

Hi bro, do you succes do full screen in mobile browser? Mind to share?

I spent a few minutes on this and tried it out. Could not figure it out immediately, but there is a Fullscreen api:
http://www.cocos2d-x.org/docs/creator-api/en/classes/screen.html?h=screen

Something like:
new cc.screen().requestFullScreen(null, () => {
cc.log(‘now fullscreen’);
});

But I do understand that this doesn’t work because I think cc.screen is a singleton. You have to somehow getInstance() of it. Did not figure it out yet.

there is also cc.view.enableAutoFullScreen(true); not exactly sure what it does.

Maybe someone else can pitch in on this?

@phero_constructs do you have any input on this one? I’m asking you here, since I noticed earlier that you seem to have good control over Cocos Creator and in the Typescript version of it :slight_smile:

Hah, thanks but not really :slight_smile:

Anyway. You enter fullscreen by using cc.screen.requestFullScreen() but this won’t work on mobile browsers because they don’t allow it.

If you want a full screen browser you have to either make an app or create a link on your home screen.

Thanks for your fast response @phero_constructs! :slight_smile:

new cc.screen().requestFullScreen(null, () => {
  cc.log('now fullscreen');
});

leads to:
Uncaught TypeError: cc.screen is not a constructor in the browser

if you don’t create a new cc.screen you obviously end up with [ts] Value of type 'typeof screen' is not callable. Did you mean to include 'new'? typescript error.

Not sure how to get the instance of cc.screen the correct way to make it work.

Any ideas?

it’s cc.screen.requestFullScreen()

[ts] Property 'requestFullScreen' does not exist on type 'typeof screen'.

because screen is a class
export class screen {. Have to get the instance somehow? :confused:

That’s strange. If I enter this into the dev console my game goes fullscreen. Can you try that?
Maybe you are doing it too early.

Interesting, it did work from the console and also from the code (triggering it from a button). But seems the Typescript types aren’t up to date since it throws a TS-error for it.

Anyway, it does work.

Thank you!

It happens that the TS definition file is not 100% correct.
If you wanna avoid the VS Code error you could write cc.screen['requestFullScreen']() and it won’t complain.

Smart!, Thank you! That’s perfect :slight_smile: