Skip to content

Commit db2e373

Browse files
committed
Fullscreen mode now uses window.outerWidth/Height when using EXACT_FIT as the scale mode, which fixes input coordinate errors (fixes phaserjs#232)
Fullscreen mode now works in Internet Explorer and uses the new fullscreen non-prefix call.
1 parent 7412490 commit db2e373

6 files changed

Lines changed: 105 additions & 30 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Bug Fixes:
163163
* Swapping between tabs will now pause the game correctly on mobile browsers (iOS7+)
164164
* Swapping between tabs will pause and resume tweens correctly, allowing their onComplete events to still fire (fixes #292)
165165
* Fullscreen mode now uses window.outerWidth/Height when using EXACT_FIT as the scale mode, which fixes input coordinate errors (fixes #232)
166+
* Fullscreen mode now works in Internet Explorer and uses the new fullscreen non-prefix call.
166167

167168

168169
TO DO:

examples/wip/fullscreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function onLeaveFullScreen() {
5151

5252
function gofull() {
5353

54-
game.scale.startFullScreen();
54+
game.scale.startFullScreen(false);
5555

5656
}
5757

examples/wip/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ function printJSLinks($dir, $files) {
106106
<input type="button" id="step" value="step" />
107107
<input type="button" id="start" value="start" style="margin-left: 32px" />
108108

109+
<div style="padding: 32px">
110+
109111
<h2>work in progress examples</h2>
110112

111113
<?php
112114
echo printJSLinks('wip', $files);
113115
?>
114116

117+
</div>
118+
115119
</body>
116120
</html>

src/core/Game.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ Phaser.Game.prototype = {
394394

395395
this.isBooted = true;
396396

397-
this.device = new Phaser.Device();
397+
this.device = new Phaser.Device(this);
398398
this.math = Phaser.Math;
399399
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
400400

@@ -403,6 +403,8 @@ Phaser.Game.prototype = {
403403

404404
this.setUpRenderer();
405405

406+
this.device.checkFullScreenSupport();
407+
406408
this.world = new Phaser.World(this);
407409
this.add = new Phaser.GameObjectFactory(this);
408410
this.make = new Phaser.GameObjectCreator(this);

src/core/ScaleManager.js

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -262,35 +262,26 @@ Phaser.ScaleManager.prototype = {
262262
*/
263263
startFullScreen: function (antialias) {
264264

265-
if (this.isFullScreen)
265+
if (this.isFullScreen || !this.game.device.fullscreen)
266266
{
267267
return;
268268
}
269269

270270
if (typeof antialias !== 'undefined' && this.game.renderType === Phaser.CANVAS)
271271
{
272-
Phaser.Canvas.setSmoothingEnabled(this.game.context, antialias);
272+
this.game.stage.smoothed = antialias;
273273
}
274274

275-
var element = this.game.canvas;
276-
277275
this._width = this.width;
278276
this._height = this.height;
279277

280-
// This needs updating to match the final spec:
281-
// http://generatedcontent.org/post/70347573294/is-your-fullscreen-api-code-up-to-date-find-out-how-to
282-
283-
if (element['requestFullScreen'])
278+
if (this.game.device.fullscreenKeyboard)
284279
{
285-
element['requestFullScreen']();
280+
this.game.canvas[this.game.device.requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
286281
}
287-
else if (element['mozRequestFullScreen'])
288-
{
289-
element.parentNode['mozRequestFullScreen']();
290-
}
291-
else if (element['webkitRequestFullScreen'])
282+
else
292283
{
293-
element['webkitRequestFullScreen'](Element.ALLOW_KEYBOARD_INPUT);
284+
this.game.canvas[this.game.device.requestFullscreen]();
294285
}
295286

296287
},
@@ -301,18 +292,7 @@ Phaser.ScaleManager.prototype = {
301292
*/
302293
stopFullScreen: function () {
303294

304-
if (document['cancelFullScreen'])
305-
{
306-
document['cancelFullScreen']();
307-
}
308-
else if (document['mozCancelFullScreen'])
309-
{
310-
document['mozCancelFullScreen']();
311-
}
312-
else if (document['webkitCancelFullScreen'])
313-
{
314-
document['webkitCancelFullScreen']();
315-
}
295+
this.game.canvas[this.game.device.cancelFullscreen]();
316296

317297
},
318298

src/system/Device.js

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
* @constructor
1212
*/
1313

14-
Phaser.Device = function () {
14+
Phaser.Device = function (game) {
15+
16+
/**
17+
* @property {Phaser.Game} game - A reference to the currently running game.
18+
*/
19+
this.game = game;
1520

1621
/**
1722
* An optional 'fix' for the horrendous Android stock browser bug https://code.google.com/p/android/issues/detail?id=39247
@@ -325,6 +330,30 @@ Phaser.Device = function () {
325330
*/
326331
this.littleEndian = false;
327332

333+
/**
334+
* @property {boolean} fullscreen - Does the browser support the Full Screen API?
335+
* @default
336+
*/
337+
this.fullscreen = false;
338+
339+
/**
340+
* @property {string} requestFullscreen - If the browser supports the Full Screen API this holds the call you need to use to activate it.
341+
* @default
342+
*/
343+
this.requestFullscreen = '';
344+
345+
/**
346+
* @property {string} cancelFullscreen - If the browser supports the Full Screen API this holds the call you need to use to cancel it.
347+
* @default
348+
*/
349+
this.cancelFullscreen = '';
350+
351+
/**
352+
* @property {boolean} fullscreenKeyboard - Does the browser support access to the Keyboard during Full Screen mode?
353+
* @default
354+
*/
355+
this.fullscreenKeyboard = false;
356+
328357
// Run the checks
329358
this._checkAudio();
330359
this._checkBrowser();
@@ -422,6 +451,65 @@ Phaser.Device.prototype = {
422451

423452
this.quirksMode = (document.compatMode === 'CSS1Compat') ? false : true;
424453

454+
455+
456+
},
457+
458+
/**
459+
* Checks for support of the Full Screen API.
460+
*
461+
* @method Phaser.Device#checkFullScreenSupport
462+
*/
463+
checkFullScreenSupport: function () {
464+
465+
var fs = [
466+
'requestFullscreen',
467+
'requestFullScreen',
468+
'webkitRequestFullscreen',
469+
'webkitRequestFullScreen',
470+
'msRequestFullscreen',
471+
'msRequestFullScreen',
472+
'mozRequestFullScreen',
473+
'mozRequestFullscreen'
474+
];
475+
476+
for (var i = 0; i < fs.length; i++)
477+
{
478+
if (this.game.canvas[fs[i]])
479+
{
480+
this.fullscreen = true;
481+
this.requestFullscreen = fs[i];
482+
}
483+
}
484+
485+
var cfs = [
486+
'cancelFullScreen',
487+
'exitFullscreen',
488+
'webkitCancelFullScreen',
489+
'webkitExitFullscreen',
490+
'msCancelFullScreen',
491+
'msExitFullscreen',
492+
'mozCancelFullScreen',
493+
'mozExitFullscreen'
494+
];
495+
496+
if (this.fullscreen)
497+
{
498+
for (var i = 0; i < cfs.length; i++)
499+
{
500+
if (this.game.canvas[cfs[i]])
501+
{
502+
this.cancelFullscreen = cfs[i];
503+
}
504+
}
505+
}
506+
507+
// Keyboard Input?
508+
if (window['Element'] && Element['ALLOW_KEYBOARD_INPUT'])
509+
{
510+
this.fullscreenKeyboard = true;
511+
}
512+
425513
},
426514

427515
/**

0 commit comments

Comments
 (0)