Skip to content

Commit a486bf6

Browse files
committed
Phaser now running on iOS. Also fixed a legacy bug where a pending sound wouldn't play once it was touch unlocked. Also fixed Input not working on WebGL contexts. Added WebGL texture updates to the Group/World swap functions.
1 parent 5da0e42 commit a486bf6

17 files changed

Lines changed: 337 additions & 200 deletions

File tree

examples/input1.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
</head>
99
<body>
1010

11+
<input type="text" id="mx" value="0" />
12+
<input type="text" id="my" value="0" />
13+
14+
<br />
15+
1116
<script type="text/javascript">
1217

1318
(function () {
@@ -31,6 +36,8 @@ function newMushroom(pointer) {
3136
}
3237

3338
function update() {
39+
document.getElementById('mx').value = game.input.x;
40+
document.getElementById('my').value = game.input.y;
3441
}
3542

3643
})();

examples/input2.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>phaser.js - a new beginning</title>
5+
<?php
6+
require('js.php');
7+
?>
8+
<style type="text/css">
9+
body {
10+
margin: 0;
11+
}
12+
</style>
13+
</head>
14+
<body>
15+
16+
<script type="text/javascript">
17+
18+
(function () {
19+
20+
var game = new Phaser.Game(400, 300, Phaser.AUTO, '', { preload: preload, create: create, update: update });
21+
22+
function preload() {
23+
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
24+
}
25+
26+
var m;
27+
28+
function create() {
29+
30+
// game.stage.canvas.style['-webkit-transform-origin'] = 'top left';
31+
// game.stage.canvas.style['-webkit-transform'] = 'scale(3,3)';
32+
33+
// game.stage.scaleMode = Phaser.StageScaleMode.EXACT_FIT;
34+
// game.stage.scale.
35+
// game.stage.scale.setScreenSize();
36+
37+
m = game.add.sprite(0, 0, 'mushroom');
38+
m.anchor.setTo(0.5, 0.5);
39+
40+
// game.input.onDown.add(newMushroom, this);
41+
42+
}
43+
44+
function newMushroom(pointer) {
45+
// game.add.sprite(pointer.x, pointer.y, 'mushroom');
46+
}
47+
48+
function update() {
49+
50+
m.x = game.input.x;
51+
m.y = game.input.y;
52+
53+
}
54+
55+
})();
56+
57+
</script>
58+
59+
</body>
60+
</html>

examples/sound1.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function preload() {
2626

2727
function create() {
2828

29-
game.world._stage.backgroundColorString = '#182d3b';
29+
game.stage.backgroundColor = '#182d3b';
3030

3131
music = game.add.audio('boden');
3232
music.play();
@@ -37,15 +37,11 @@ function create() {
3737
}
3838

3939
function update() {
40-
4140
s.rotation += 0.01;
42-
4341
}
4442

4543
function render() {
46-
4744
game.debug.renderSoundInfo(music, 20, 32);
48-
4945
}
5046

5147
})();

src/core/Game.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,11 @@ Phaser.Game.prototype = {
312312

313313
this.load.onLoadComplete.add(this.loadComplete, this);
314314

315+
this.stage.boot();
315316
this.world.boot();
316317
this.state.boot();
317318
this.input.boot();
319+
this.sound.boot();
318320

319321
if (this.renderType == Phaser.CANVAS)
320322
{
@@ -355,7 +357,7 @@ Phaser.Game.prototype = {
355357
else
356358
{
357359
// They must have requested WebGL and their browser supports it
358-
this.renderer = new PIXI.WebGLRenderer(this.width, this.height, null, this.transparent, this.antialias);
360+
this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias);
359361
this.canvas = this.renderer.view;
360362
this.context = null;
361363
}

src/core/Group.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ Phaser.Group.prototype = {
132132
if (child1Prev) { child1Prev._iNext = child2; }
133133
if (child2Next) { child2Next._iPrev = child1; }
134134

135+
if (child1.__renderGroup)
136+
{
137+
child1.__renderGroup.updateTexture(child1);
138+
}
139+
140+
if (child2.__renderGroup)
141+
{
142+
child2.__renderGroup.updateTexture(child2);
143+
}
144+
135145
return true;
136146
}
137147
else if (child2._iNext == child1)
@@ -145,6 +155,16 @@ Phaser.Group.prototype = {
145155
if (child2Prev) { child2Prev._iNext = child1; }
146156
if (child1Next) { child2Next._iPrev = child2; }
147157

158+
if (child1.__renderGroup)
159+
{
160+
child1.__renderGroup.updateTexture(child1);
161+
}
162+
163+
if (child2.__renderGroup)
164+
{
165+
child2.__renderGroup.updateTexture(child2);
166+
}
167+
148168
return true;
149169
}
150170
else
@@ -160,6 +180,16 @@ Phaser.Group.prototype = {
160180
if (child2Prev) { child2Prev._iNext = child1; }
161181
if (child2Next) { child2Next._iPrev = child1; }
162182

183+
if (child1.__renderGroup)
184+
{
185+
child1.__renderGroup.updateTexture(child1);
186+
}
187+
188+
if (child2.__renderGroup)
189+
{
190+
child2.__renderGroup.updateTexture(child2);
191+
}
192+
163193
return true;
164194
}
165195

src/core/Stage.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,11 @@ Phaser.Stage = function (game, width, height) {
2727
// The Pixi Stage which is hooked to the renderer
2828
this._stage = new PIXI.Stage(0x000000, false);
2929
this._stage.name = '_stage_root';
30-
31-
Phaser.Canvas.getOffset(this.canvas, this.offset);
32-
33-
this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, this.game.width, this.game.height);
34-
30+
3531
this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
3632
this.scale = new Phaser.StageScaleMode(this.game, width, height);
3733
this.aspectRatio = width / height;
3834

39-
var _this = this;
40-
41-
this._onChange = function (event) {
42-
return _this.visibilityChange(event);
43-
}
44-
45-
document.addEventListener('visibilitychange', this._onChange, false);
46-
document.addEventListener('webkitvisibilitychange', this._onChange, false);
47-
document.addEventListener('pagehide', this._onChange, false);
48-
document.addEventListener('pageshow', this._onChange, false);
49-
50-
window.onblur = this._onChange;
51-
window.onfocus = this._onChange;
52-
5335
};
5436

5537
Phaser.Stage.prototype = {
@@ -60,6 +42,28 @@ Phaser.Stage.prototype = {
6042
bounds: null,
6143
offset: null,
6244

45+
boot: function () {
46+
47+
Phaser.Canvas.getOffset(this.canvas, this.offset);
48+
49+
this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, this.game.width, this.game.height);
50+
51+
var _this = this;
52+
53+
this._onChange = function (event) {
54+
return _this.visibilityChange(event);
55+
}
56+
57+
document.addEventListener('visibilitychange', this._onChange, false);
58+
document.addEventListener('webkitvisibilitychange', this._onChange, false);
59+
document.addEventListener('pagehide', this._onChange, false);
60+
document.addEventListener('pageshow', this._onChange, false);
61+
62+
window.onblur = this._onChange;
63+
window.onfocus = this._onChange;
64+
65+
},
66+
6367
/**
6468
* This method is called when the document visibility is changed.
6569
*/

src/core/World.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ Phaser.World.prototype = {
148148
if (child1Prev) { child1Prev._iNext = child2; }
149149
if (child2Next) { child2Next._iPrev = child1; }
150150

151+
if (child1.__renderGroup)
152+
{
153+
child1.__renderGroup.updateTexture(child1);
154+
}
155+
156+
if (child2.__renderGroup)
157+
{
158+
child2.__renderGroup.updateTexture(child2);
159+
}
160+
151161
return true;
152162
}
153163
else if (child2._iNext == child1)
@@ -161,6 +171,16 @@ Phaser.World.prototype = {
161171
if (child2Prev) { child2Prev._iNext = child1; }
162172
if (child1Next) { child2Next._iPrev = child2; }
163173

174+
if (child1.__renderGroup)
175+
{
176+
child1.__renderGroup.updateTexture(child1);
177+
}
178+
179+
if (child2.__renderGroup)
180+
{
181+
child2.__renderGroup.updateTexture(child2);
182+
}
183+
164184
return true;
165185
}
166186
else
@@ -176,6 +196,16 @@ Phaser.World.prototype = {
176196
if (child2Prev) { child2Prev._iNext = child1; }
177197
if (child2Next) { child2Next._iPrev = child1; }
178198

199+
if (child1.__renderGroup)
200+
{
201+
child1.__renderGroup.updateTexture(child1);
202+
}
203+
204+
if (child2.__renderGroup)
205+
{
206+
child2.__renderGroup.updateTexture(child2);
207+
}
208+
179209
return true;
180210
}
181211

src/input/MSPointer.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ Phaser.MSPointer.prototype = {
5252
return _this.onPointerUp(event);
5353
};
5454

55-
this.game.stage.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
56-
this.game.stage.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
57-
this.game.stage.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
55+
this.game.renderer.view.addEventListener('MSPointerDown', this._onMSPointerDown, false);
56+
this.game.renderer.view.addEventListener('MSPointerMove', this._onMSPointerMove, false);
57+
this.game.renderer.view.addEventListener('MSPointerUp', this._onMSPointerUp, false);
5858

59-
this.game.stage.canvas.style['-ms-content-zooming'] = 'none';
60-
this.game.stage.canvas.style['-ms-touch-action'] = 'none';
59+
this.game.renderer.view.style['-ms-content-zooming'] = 'none';
60+
this.game.renderer.view.style['-ms-touch-action'] = 'none';
6161

6262
}
6363

src/input/Mouse.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ Phaser.Mouse.prototype = {
5555
return _this.onMouseUp(event);
5656
};
5757

58-
this.game.stage.canvas.addEventListener('mousedown', this._onMouseDown, true);
59-
this.game.stage.canvas.addEventListener('mousemove', this._onMouseMove, true);
60-
this.game.stage.canvas.addEventListener('mouseup', this._onMouseUp, true);
58+
this.game.renderer.view.addEventListener('mousedown', this._onMouseDown, true);
59+
this.game.renderer.view.addEventListener('mousemove', this._onMouseMove, true);
60+
this.game.renderer.view.addEventListener('mouseup', this._onMouseUp, true);
61+
6162
},
6263

6364
/**

src/input/Pointer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ Phaser.Pointer.prototype = {
242242
{
243243
this.game.input.x = this.x * this.game.input.scale.x;
244244
this.game.input.y = this.y * this.game.input.scale.y;
245-
// this.game.input.x = this.x;
246-
// this.game.input.y = this.y;
247245
this.game.input.position.setTo(this.x, this.y);
248246
this.game.input.onDown.dispatch(this);
249247
this.game.input.resetSpeed(this.x, this.y);

0 commit comments

Comments
 (0)