Skip to content

Commit 14ee4c2

Browse files
committed
Added Camera and fixed path issues.
1 parent a081ae8 commit 14ee4c2

8 files changed

Lines changed: 367 additions & 33 deletions

File tree

v3/src/boot/Game.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ Game.prototype = {
110110
// timestamp = DOMHighResTimeStamp
111111
update: function (timestamp)
112112
{
113-
// console.log(timestamp);
114-
// this.state.step(timestamp);
113+
this.state.step(timestamp);
115114
}
116115

117116
};

v3/src/camera/Camera.js

Lines changed: 341 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,341 @@
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+
var Component = require('../components');
8+
9+
/**
10+
* 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.
11+
* The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y
12+
*
13+
* @class Phaser.Camera
14+
* @constructor
15+
* @param {Phaser.Game} game - Game reference to the currently running game.
16+
* @param {number} id - Not being used at the moment, will be when Phaser supports multiple camera
17+
* @param {number} x - Position of the camera on the X axis
18+
* @param {number} y - Position of the camera on the Y axis
19+
* @param {number} width - The width of the view rectangle
20+
* @param {number} height - The height of the view rectangle
21+
*/
22+
var Camera = function (state, x, y, viewportWidth, viewportHeight)
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.viewportWidth = viewportWidth;
37+
38+
this.viewportHeight = viewportHeight;
39+
40+
this.transform = new 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+
Camera.prototype.constructor = Camera;
60+
61+
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.viewportWidth;
82+
var vy = this.y;
83+
var vh = this.y + this.viewportHeight;
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+
Object.defineProperties(Camera.prototype, {
139+
140+
// Transform getters / setters
141+
142+
x: {
143+
144+
enumerable: true,
145+
146+
get: function ()
147+
{
148+
return this.transform._posX;
149+
},
150+
151+
set: function (value)
152+
{
153+
this.transform._posX = value;
154+
this.transform.dirty = true;
155+
}
156+
157+
},
158+
159+
y: {
160+
161+
enumerable: true,
162+
163+
get: function ()
164+
{
165+
return this.transform._posY;
166+
},
167+
168+
set: function (value)
169+
{
170+
this.transform._posY = value;
171+
this.transform.dirty = true;
172+
}
173+
174+
},
175+
176+
right: {
177+
178+
enumerable: true,
179+
180+
get: function ()
181+
{
182+
return this.transform._posX + (this.viewportWidth * this.transform._scaleX);
183+
}
184+
185+
},
186+
187+
bottom: {
188+
189+
enumerable: true,
190+
191+
get: function ()
192+
{
193+
return this.transform._posY + (this.viewportHeight * this.transform._scaleY);
194+
}
195+
196+
},
197+
198+
scale: {
199+
200+
enumerable: true,
201+
202+
get: function ()
203+
{
204+
return this.transform._scaleX;
205+
},
206+
207+
set: function (value)
208+
{
209+
this.transform._scaleX = value;
210+
this.transform._scaleY = value;
211+
this.transform.dirty = true;
212+
this.transform.updateCache();
213+
}
214+
215+
},
216+
217+
scaleX: {
218+
219+
enumerable: true,
220+
221+
get: function ()
222+
{
223+
return this.transform._scaleX;
224+
},
225+
226+
set: function (value)
227+
{
228+
this.transform._scaleX = value;
229+
this.transform.dirty = true;
230+
this.transform.updateCache();
231+
}
232+
233+
},
234+
235+
scaleY: {
236+
237+
enumerable: true,
238+
239+
get: function ()
240+
{
241+
return this.transform._scaleY;
242+
},
243+
244+
set: function (value)
245+
{
246+
this.transform._scaleY = value;
247+
this.transform.dirty = true;
248+
this.transform.updateCache();
249+
}
250+
251+
},
252+
253+
pivotX: {
254+
255+
enumerable: true,
256+
257+
get: function ()
258+
{
259+
return this.transform._pivotX;
260+
},
261+
262+
set: function (value)
263+
{
264+
this.transform._pivotX = value;
265+
this.transform.dirty = true;
266+
this.transform.updateCache();
267+
}
268+
269+
},
270+
271+
pivotY: {
272+
273+
enumerable: true,
274+
275+
get: function ()
276+
{
277+
return this.transform._pivotY;
278+
},
279+
280+
set: function (value)
281+
{
282+
this.transform._pivotY = value;
283+
this.transform.dirty = true;
284+
this.transform.updateCache();
285+
}
286+
287+
},
288+
289+
angle: {
290+
291+
enumerable: true,
292+
293+
get: function ()
294+
{
295+
return Phaser.Math.wrapAngle(this.rotation * Phaser.Math.RAD_TO_DEG);
296+
},
297+
298+
set: function (value)
299+
{
300+
this.rotation = Phaser.Math.wrapAngle(value) * Phaser.Math.DEG_TO_RAD;
301+
}
302+
303+
},
304+
305+
rotation: {
306+
307+
enumerable: true,
308+
309+
get: function ()
310+
{
311+
return this.transform._rotation;
312+
},
313+
314+
set: function (value)
315+
{
316+
if (this.transform._rotation === value)
317+
{
318+
return;
319+
}
320+
321+
this.transform._rotation = value;
322+
this.transform.dirty = true;
323+
324+
if (this.transform._rotation % Phaser.Math.PI2)
325+
{
326+
this.transform.cache.sr = Math.sin(this.transform._rotation);
327+
this.transform.cache.cr = Math.cos(this.transform._rotation);
328+
this.transform.updateCache();
329+
this.transform.hasLocalRotation = true;
330+
}
331+
else
332+
{
333+
this.transform.hasLocalRotation = false;
334+
}
335+
}
336+
337+
}
338+
339+
});
340+
341+
module.exports = Camera;

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'f1712ef0-bc24-11e6-a204-b96b8023346c'
2+
build: '66ef5980-bc26-11e6-b62b-c7bd5e19f5c7'
33
};
44
module.exports = CHECKSUM;

v3/src/renderer/webgl/batches/MultiTextureBatch.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,6 @@ MultiTextureBatch.prototype.destroy = function ()
383383

384384
this.manager = null;
385385
};
386+
387+
module.exports = MultiTextureBatch;
388+

v3/src/renderer/webgl/batches/SingleTextureBatch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var SingleTextureBatch = function (manager, batchSize)
2727

2828
var vertSize = (4 * 2) + (4 * 2) + (4) + (4) + (4);
2929

30-
Phaser.Renderer.WebGL.Batch.call(this, manager, batchSize, vertSize);
30+
BaseBatch.call(this, manager, batchSize, vertSize);
3131

3232
this.type = 1;
3333

v3/src/renderer/webgl/utils/CreateEmptyTexture.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
var CONST = require('../../../const');
2+
13
var CreateEmptyTexture = function (gl, width, height, scaleMode, textureIndex)
24
{
35
var texture = gl.createTexture();
4-
var glScaleMode = (scaleMode === Phaser.scaleModes.LINEAR) ? gl.LINEAR : gl.NEAREST;
6+
var glScaleMode = (scaleMode === CONST.scaleModes.LINEAR) ? gl.LINEAR : gl.NEAREST;
57

68
gl.activeTexture(gl.TEXTURE0 + textureIndex);
79
gl.bindTexture(gl.TEXTURE_2D, texture);

v3/src/state/StateManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var State = require('./State');
1010
var Settings = require('./Settings');
1111
var Systems = require('./Systems');
1212
var GetObjectValue = require('../utils/GetObjectValue');
13-
var LoaderEvent = require('../loader/events/');
13+
// var LoaderEvent = require('../loader/events/');
1414

1515
/**
1616
* The State Manager is responsible for loading, setting up and switching game states.

0 commit comments

Comments
 (0)