Skip to content

Commit 7412490

Browse files
committed
ScaleManager has 2 new events: ScaleManager.enterFullScreen and ScaleManager.leaveFullScreen, so you can respond to fullscreen changes directly.
Fullscreen mode now uses window.outerWidth/Height when using EXACT_FIT as the scale mode, which fixes input coordinate errors (fixes phaserjs#232)
1 parent be27442 commit 7412490

5 files changed

Lines changed: 138 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Updates:
139139
* Phaser.Input.Key.isUp now defaults to 'true', as does GamepadButton.isUp (#474)
140140
* Vastly improved visibility API support + pageshow/pagehide + focus/blur. Working across Chrome, IE, Firefox, iOS, Android (also fixes #161)
141141
* Pausing the game will now mute audio and resuming will un-mute, unless it was muted via the game (fixes #439)
142+
* ScaleManager has 2 new events: ScaleManager.enterFullScreen and ScaleManager.leaveFullScreen, so you can respond to fullscreen changes directly.
142143

143144

144145
Bug Fixes:
@@ -161,6 +162,7 @@ Bug Fixes:
161162
* Active animations now monitor if the game pauses, and resume normally when the game un-pauses (fixes #179)
162163
* Swapping between tabs will now pause the game correctly on mobile browsers (iOS7+)
163164
* Swapping between tabs will pause and resume tweens correctly, allowing their onComplete events to still fire (fixes #292)
165+
* Fullscreen mode now uses window.outerWidth/Height when using EXACT_FIT as the scale mode, which fixes input coordinate errors (fixes #232)
164166

165167

166168
TO DO:
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
function preload() {
5+
6+
game.load.image('dragon', 'assets/pics/cougar_dragonsun.png');
7+
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
8+
9+
}
10+
11+
var button;
12+
var sprite;
13+
14+
function create() {
15+
16+
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dragon');
17+
sprite.anchor.set(0.5);
18+
19+
game.stage.backgroundColor = '#000';
20+
21+
// Stretch to fill
22+
game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT;
23+
24+
// Keep original size
25+
// game.scale.fullScreenScaleMode = Phaser.ScaleManager.NO_SCALE;
26+
27+
// Maintain aspect ratio
28+
// game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
29+
30+
button = game.add.button(game.world.centerX - 95, 500, 'button', actionOnClick, this, 2, 1, 0);
31+
button.visible = false;
32+
33+
game.scale.enterFullScreen.add(onEnterFullScreen, this);
34+
game.scale.leaveFullScreen.add(onLeaveFullScreen, this);
35+
36+
game.input.onDown.add(gofull, this);
37+
38+
}
39+
40+
function onEnterFullScreen() {
41+
42+
button.visible = true;
43+
44+
}
45+
46+
function onLeaveFullScreen() {
47+
48+
button.visible = false;
49+
50+
}
51+
52+
function gofull() {
53+
54+
game.scale.startFullScreen();
55+
56+
}
57+
58+
function actionOnClick () {
59+
60+
sprite.tint = Math.random() * 0xFFFFFF;
61+
62+
}
63+
64+
function update() {
65+
66+
}
67+
68+
function render () {
69+
70+
if (game.scale.isFullScreen)
71+
{
72+
game.debug.renderText('ESC to leave fullscreen', 270, 16);
73+
}
74+
else
75+
{
76+
game.debug.renderText('Click / Tap to go fullscreen', 270, 16);
77+
}
78+
79+
}

examples/wip/fullscreen.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:
44
function preload() {
55

66
game.load.image('dragon', 'assets/pics/cougar_dragonsun.png');
7+
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
78

89
}
910

11+
var button;
12+
var sprite;
13+
1014
function create() {
1115

12-
var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dragon');
16+
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dragon');
1317
sprite.anchor.set(0.5);
1418

1519
game.stage.backgroundColor = '#000';
@@ -23,22 +27,53 @@ function create() {
2327
// Maintain aspect ratio
2428
// game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
2529

30+
button = game.add.button(game.world.centerX - 95, 500, 'button', actionOnClick, this, 2, 1, 0);
31+
button.visible = false;
32+
33+
game.scale.enterFullScreen.add(onEnterFullScreen, this);
34+
game.scale.leaveFullScreen.add(onLeaveFullScreen, this);
35+
2636
game.input.onDown.add(gofull, this);
2737

2838
}
2939

40+
function onEnterFullScreen() {
41+
42+
button.visible = true;
43+
44+
}
45+
46+
function onLeaveFullScreen() {
47+
48+
button.visible = false;
49+
50+
}
51+
3052
function gofull() {
3153

3254
game.scale.startFullScreen();
3355

3456
}
3557

58+
function actionOnClick () {
59+
60+
sprite.tint = Math.random() * 0xFFFFFF;
61+
62+
}
63+
3664
function update() {
3765

3866
}
3967

4068
function render () {
4169

42-
game.debug.renderText('Click / Tap to go fullscreen', 270, 16);
70+
if (game.scale.isFullScreen)
71+
{
72+
game.debug.renderText('ESC to leave fullscreen', 270, 16);
73+
}
74+
else
75+
{
76+
game.debug.renderText('Click / Tap to go fullscreen', 270, 16);
77+
}
4378

4479
}

examples/wip/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ function printJSLinks($dir, $files) {
9292
?>
9393
<style>
9494
body {
95+
margin: 0;
96+
padding: 0;
9597
font-family: Arial;
9698
font-size: 14px;
9799
}

src/core/ScaleManager.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ Phaser.ScaleManager = function (game, width, height) {
120120
*/
121121
this.hasResized = new Phaser.Signal();
122122

123+
/**
124+
* @property {Phaser.Signal} enterFullScreen - The event that is dispatched when the browser enters full screen mode (if it supports the FullScreen API).
125+
*/
126+
this.enterFullScreen = new Phaser.Signal();
127+
128+
/**
129+
* @property {Phaser.Signal} leaveFullScreen - The event that is dispatched when the browser leaves full screen mode (if it supports the FullScreen API).
130+
*/
131+
this.leaveFullScreen = new Phaser.Signal();
132+
123133
/**
124134
* @property {number} orientation - The orientation value of the game (as defined by window.orientation if set). 90 = landscape. 0 = portrait.
125135
*/
@@ -323,19 +333,24 @@ Phaser.ScaleManager.prototype = {
323333
this.game.canvas.style['width'] = '100%';
324334
this.game.canvas.style['height'] = '100%';
325335

326-
this.setMaximum();
336+
this.width = window.outerWidth;
337+
this.height = window.outerHeight;
327338

328339
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
329340

330341
this.aspectRatio = this.width / this.height;
331342
this.scaleFactor.x = this.game.width / this.width;
332343
this.scaleFactor.y = this.game.height / this.height;
344+
345+
this.checkResize();
333346
}
334347
else if (this.fullScreenScaleMode === Phaser.ScaleManager.SHOW_ALL)
335348
{
336349
this.setShowAll();
337350
this.refresh();
338351
}
352+
353+
this.enterFullScreen.dispatch(this.width, this.height);
339354
}
340355
else
341356
{
@@ -350,6 +365,8 @@ Phaser.ScaleManager.prototype = {
350365
this.aspectRatio = this.width / this.height;
351366
this.scaleFactor.x = this.game.width / this.width;
352367
this.scaleFactor.y = this.game.height / this.height;
368+
369+
this.leaveFullScreen.dispatch(this.width, this.height);
353370
}
354371

355372
},

0 commit comments

Comments
 (0)