Skip to content

Commit b3c2ddb

Browse files
committed
Pre-crash salvage.
1 parent c683ae2 commit b3c2ddb

5 files changed

Lines changed: 357 additions & 9 deletions

File tree

build/phaser3-config.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
<script src="$path/src/geom/Rectangle.js"></script>
6262
<script src="$path/src/geom/RoundedRectangle.js"></script>
6363
64+
<script src="$path/src/camera/Camera.js"></script>
65+
6466
<script src="$path/src/states/State.js"></script>
6567
<script src="$path/src/states/StateManager.js"></script>
6668
<script src="$path/src/states/StateSettings.js"></script>

src/camera/Camera.js

Lines changed: 340 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,340 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2016 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view.
9+
* The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y
10+
*
11+
* @class Phaser.Camera
12+
* @constructor
13+
* @param {Phaser.Game} game - Game reference to the currently running game.
14+
* @param {number} id - Not being used at the moment, will be when Phaser supports multiple camera
15+
* @param {number} x - Position of the camera on the X axis
16+
* @param {number} y - Position of the camera on the Y axis
17+
* @param {number} width - The width of the view rectangle
18+
* @param {number} height - The height of the view rectangle
19+
*/
20+
Phaser.Camera = function (state, x, y, width, height)
21+
{
22+
console.log('Camera');
23+
24+
/**
25+
* The State that this Camera belongs to. A Camera can only belong to one State, and a State only
26+
* has one Camera.
27+
* @property {Phaser.State} state
28+
*/
29+
this.state = state;
30+
31+
/**
32+
* @property {Phaser.Game} game - A reference to the currently running Game.
33+
*/
34+
this.game = state.game;
35+
36+
this.width = width;
37+
38+
this.height = height;
39+
40+
this.transform = new Phaser.Component.Transform(this, x, y);
41+
42+
/**
43+
* The Camera is bound to this Rectangle and cannot move outside of it. By default it is enabled and set to the size of the World.
44+
* The Rectangle can be located anywhere in the world and updated as often as you like. If you don't wish the Camera to be bound
45+
* at all then set this to null. The values can be anything and are in World coordinates, with 0,0 being the top-left of the world.
46+
*
47+
* @property {Phaser.Rectangle} bounds - The Rectangle in which the Camera is bounded. Set to null to allow for movement anywhere.
48+
*/
49+
// this.bounds = new Phaser.Rectangle(x, y, width, height);
50+
51+
// this.bounds = new Phaser.Circle(x, y)
52+
53+
/**
54+
* @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not.
55+
*/
56+
this.atLimit = { x: false, y: false };
57+
};
58+
59+
Phaser.Camera.prototype.constructor = Phaser.Camera;
60+
61+
Phaser.Camera.prototype = {
62+
63+
/**
64+
* Method called to ensure the camera doesn't venture outside of the game world.
65+
* Called automatically by Camera.update.
66+
*
67+
* @method Phaser.Camera#checkBounds
68+
* @protected
69+
*/
70+
checkBounds: function ()
71+
{
72+
this.atLimit.x = false;
73+
this.atLimit.y = false;
74+
75+
// var vx = this.view.x + this._shake.x;
76+
// var vw = this.view.right + this._shake.x;
77+
// var vy = this.view.y + this._shake.y;
78+
// var vh = this.view.bottom + this._shake.y;
79+
80+
var vx = this.x;
81+
var vw = this.x + this.width;
82+
var vy = this.y;
83+
var vh = this.y + this.height;
84+
85+
// Make sure we didn't go outside the cameras bounds
86+
if (vx <= this.bounds.x * this.scale.x)
87+
{
88+
this.atLimit.x = true;
89+
this.view.x = this.bounds.x * this.scale.x;
90+
91+
if (!this._shake.shakeBounds)
92+
{
93+
// The camera is up against the bounds, so reset the shake
94+
this._shake.x = 0;
95+
}
96+
}
97+
98+
if (vw >= this.bounds.right * this.scale.x)
99+
{
100+
this.atLimit.x = true;
101+
this.view.x = (this.bounds.right * this.scale.x) - this.width;
102+
103+
if (!this._shake.shakeBounds)
104+
{
105+
// The camera is up against the bounds, so reset the shake
106+
this._shake.x = 0;
107+
}
108+
}
109+
110+
if (vy <= this.bounds.top * this.scale.y)
111+
{
112+
this.atLimit.y = true;
113+
this.view.y = this.bounds.top * this.scale.y;
114+
115+
if (!this._shake.shakeBounds)
116+
{
117+
// The camera is up against the bounds, so reset the shake
118+
this._shake.y = 0;
119+
}
120+
}
121+
122+
if (vh >= this.bounds.bottom * this.scale.y)
123+
{
124+
this.atLimit.y = true;
125+
this.view.y = (this.bounds.bottom * this.scale.y) - this.height;
126+
127+
if (!this._shake.shakeBounds)
128+
{
129+
// The camera is up against the bounds, so reset the shake
130+
this._shake.y = 0;
131+
}
132+
}
133+
134+
},
135+
136+
137+
};
138+
139+
Object.defineProperties(Phaser.Camera.prototype, {
140+
141+
// Transform getters / setters
142+
143+
x: {
144+
145+
enumerable: true,
146+
147+
get: function ()
148+
{
149+
return this.transform._posX;
150+
},
151+
152+
set: function (value)
153+
{
154+
this.transform._posX = value;
155+
this.transform.dirty = true;
156+
}
157+
158+
},
159+
160+
y: {
161+
162+
enumerable: true,
163+
164+
get: function ()
165+
{
166+
return this.transform._posY;
167+
},
168+
169+
set: function (value)
170+
{
171+
this.transform._posY = value;
172+
this.transform.dirty = true;
173+
}
174+
175+
},
176+
177+
right: {
178+
179+
enumerable: true,
180+
181+
get: function ()
182+
{
183+
return this.transform._posX + (this.width * this.transform._scaleX);
184+
}
185+
186+
},
187+
188+
bottom: {
189+
190+
enumerable: true,
191+
192+
get: function ()
193+
{
194+
return this.transform._posY + (this.height * this.transform._scaleY);
195+
}
196+
197+
},
198+
199+
scale: {
200+
201+
enumerable: true,
202+
203+
get: function ()
204+
{
205+
return this.transform._scaleX;
206+
},
207+
208+
set: function (value)
209+
{
210+
this.transform._scaleX = value;
211+
this.transform._scaleY = value;
212+
this.transform.dirty = true;
213+
this.transform.updateCache();
214+
}
215+
216+
},
217+
218+
scaleX: {
219+
220+
enumerable: true,
221+
222+
get: function ()
223+
{
224+
return this.transform._scaleX;
225+
},
226+
227+
set: function (value)
228+
{
229+
this.transform._scaleX = value;
230+
this.transform.dirty = true;
231+
this.transform.updateCache();
232+
}
233+
234+
},
235+
236+
scaleY: {
237+
238+
enumerable: true,
239+
240+
get: function ()
241+
{
242+
return this.transform._scaleY;
243+
},
244+
245+
set: function (value)
246+
{
247+
this.transform._scaleY = value;
248+
this.transform.dirty = true;
249+
this.transform.updateCache();
250+
}
251+
252+
},
253+
254+
pivotX: {
255+
256+
enumerable: true,
257+
258+
get: function ()
259+
{
260+
return this.transform._pivotX;
261+
},
262+
263+
set: function (value)
264+
{
265+
this.transform._pivotX = value;
266+
this.transform.dirty = true;
267+
this.transform.updateCache();
268+
}
269+
270+
},
271+
272+
pivotY: {
273+
274+
enumerable: true,
275+
276+
get: function ()
277+
{
278+
return this.transform._pivotY;
279+
},
280+
281+
set: function (value)
282+
{
283+
this.transform._pivotY = value;
284+
this.transform.dirty = true;
285+
this.transform.updateCache();
286+
}
287+
288+
},
289+
290+
angle: {
291+
292+
enumerable: true,
293+
294+
get: function ()
295+
{
296+
return Phaser.Math.wrapAngle(this.rotation * Phaser.Math.RAD_TO_DEG);
297+
},
298+
299+
set: function (value)
300+
{
301+
this.rotation = Phaser.Math.wrapAngle(value) * Phaser.Math.DEG_TO_RAD;
302+
}
303+
304+
},
305+
306+
rotation: {
307+
308+
enumerable: true,
309+
310+
get: function ()
311+
{
312+
return this.transform._rotation;
313+
},
314+
315+
set: function (value)
316+
{
317+
if (this.transform._rotation === value)
318+
{
319+
return;
320+
}
321+
322+
this.transform._rotation = value;
323+
this.transform.dirty = true;
324+
325+
if (this.transform._rotation % Phaser.Math.PI2)
326+
{
327+
this.transform.cache.sr = Math.sin(this.transform._rotation);
328+
this.transform.cache.cr = Math.cos(this.transform._rotation);
329+
this.transform.updateCache();
330+
this.transform.hasLocalRotation = true;
331+
}
332+
else
333+
{
334+
this.transform.hasLocalRotation = false;
335+
}
336+
}
337+
338+
}
339+
340+
});

src/core/Game.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ Phaser.Game.prototype = {
621621

622622
// this.world = new Phaser.World(this);
623623

624+
console.log('UpdateManager alive');
625+
624626
this.updates = new Phaser.UpdateManager(this);
625627

626628
// this.state = new Phaser.StateManager(this, this._pendingState);
@@ -728,8 +730,8 @@ Phaser.Game.prototype = {
728730
* @method Phaser.Game#setUpRenderer
729731
* @protected
730732
*/
731-
setUpRenderer: function () {
732-
733+
setUpRenderer: function ()
734+
{
733735
if (this.config['canvas'])
734736
{
735737
this.canvas = this.config['canvas'];
@@ -963,7 +965,7 @@ Phaser.Game.prototype = {
963965
// this.tweens.update();
964966

965967
// this.sound.update();
966-
// this.input.update();
968+
this.input.update();
967969
// this.physics.update();
968970
// this.particles.update();
969971
// this.plugins.update();

src/states/State.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313
Phaser.State = function (config)
1414
{
15+
console.log('State.cstr');
16+
1517
// The properties a State *must* have, that cannot be changed without breaking it:
1618

1719
this.game = null;
@@ -20,10 +22,6 @@ Phaser.State = function (config)
2022

2123
this.sys = new Phaser.State.Systems(this, config);
2224

23-
// Needs to have its own Renderer - can make 1 draw call per State if smart enough
24-
// Use a shared canvas though. Or
25-
this.renderer;
26-
2725
// Reference to sys.children, set during sys.init only
2826
this.children;
2927
};

0 commit comments

Comments
 (0)