kittykatattack / ga

The world's tiniest, cutest and funnest game engine
451 stars 84 forks source link

A better fullscreen module? #33

Open kittykatattack opened 9 years ago

kittykatattack commented 9 years ago

Right now Ga has a very simple way of launching a game in fullscreen mode (Using the WHATWG Fullscreen API):

enableFullscreen();

(You'll find this function in plugins.js and a working example in tutorials/05_flappyFairy.html) This launches fullscreen mode as soon as the user clicks or touches the game canvas. Pressing esc exits fullscreen mode. But you can also assign your own custom keyboard keys to exit fullscreen by optionally listing their ascii key code values in enableFullscreen's arguments, like this :

enableFullscreen(88, 120);

88 is lowercase x, and 120 is uppercase X. Pressing either of these keys will exit fullscreen mode.

The fullscreen API only allows fullscreen mode to be launched directly from user-intiated events attached to HTML elements. Ga only has one HTML element: the canvas. That means enableFullscreen works by checking to see if the canvas has been clicked, and then launching fullscreen mode if it has. And it also means that's not possible to launch fullscreen mode using Ga's button object. So, for example, you can't code something like this:

anyButton.release = function() {
  enableFullscreen();
};

That's because Ga's buttons are just JavaScript objects - not HTML elements. Obviously, this is not ideal. It would be great to have buttons that launch, exit, and toggle fullscreen mode directly in the game canvas, without needing to overlay any HTML elements to allow this.

But how? Can anyone suggest some clever solutions?

kittykatattack commented 9 years ago

I think I found a solution: do a hit test on the button and call enableFullscreen if the pointer is inside the button's area. That should make a fullscreen toggle button possible too, just using canvas-based buttons. I will try it and report back! :)

kittykatattack commented 9 years ago

... It doesn't work :confused: It just flags fullscreen mode to activate on the next pointer interaction. I will look for another solution! :rocket: