Skip to content

Commit 4b7fc8d

Browse files
committed
Change to boot order to try and resolve short-TTL timers.
1 parent 7ba1196 commit 4b7fc8d

3 files changed

Lines changed: 63 additions & 151 deletions

File tree

build/phaser.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1748,7 +1748,7 @@ declare module Phaser {
17481748
separate(body: Phaser.Physics.Arcade.Body, body2: Phaser.Physics.Arcade.Body, processCallback: Function, callbackContext: any, overlapOnly: boolean): boolean;
17491749
intersects(a: Phaser.Physics.Arcade.Body, b: Phaser.Physics.Arcade.Body): boolean;
17501750
tileIntersects(body: Phaser.Physics.Arcade.Body, tile: Phaser.Tile): boolean;
1751-
separateTiles(body: Phaser.Physics.Arcade.Body, tile: <Phaser.Tile>Array): boolean;
1751+
separateTiles(body: Phaser.Physics.Arcade.Body, tile: Array<Phaser.Tile>): boolean;
17521752
separateTile(body: Phaser.Physics.Arcade.Body, tile: Phaser.Tile): boolean;
17531753
processTileSeparation(body: Phaser.Physics.Arcade.Body): boolean;
17541754
moveToObject(displayObject: Phaser.Sprite, destination: Phaser.Sprite, speed?: number, maxTime?: number): number;

src/core/Game.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ Phaser.Game.prototype = {
457457
this.world.boot();
458458
this.input.boot();
459459
this.sound.boot();
460-
this.state.boot();
461460

462461
this.load.onLoadComplete.add(this.loadComplete, this);
463462

@@ -469,6 +468,7 @@ Phaser.Game.prototype = {
469468
this.raf = new Phaser.RequestAnimationFrame(this);
470469
this.raf.start();
471470

471+
this.state.boot();
472472
}
473473

474474
},

src/gameobjects/Image.js

Lines changed: 61 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -60,68 +60,9 @@ Phaser.Image = function (game, x, y, key, frame) {
6060

6161
this.currentFrame = new Phaser.Rectangle();
6262

63-
if (key instanceof Phaser.RenderTexture)
64-
{
65-
PIXI.Sprite.call(this, key);
66-
67-
this.currentFrame = this.game.cache.getTextureFrame(key.name);
68-
}
69-
else if (key instanceof Phaser.BitmapData)
70-
{
71-
PIXI.Sprite.call(this, key.texture, key.textureFrame);
72-
73-
this.currentFrame = key.textureFrame;
74-
}
75-
else if (key instanceof PIXI.Texture)
76-
{
77-
PIXI.Sprite.call(this, key);
78-
79-
this.currentFrame = frame;
80-
}
81-
else
82-
{
83-
if (key === null || typeof key === 'undefined')
84-
{
85-
key = '__default';
86-
this.key = key;
87-
}
88-
else if (typeof key === 'string' && this.game.cache.checkImageKey(key) === false)
89-
{
90-
key = '__missing';
91-
this.key = key;
92-
}
63+
PIXI.Sprite.call(this, PIXI.TextureCache['__default']);
9364

94-
PIXI.Sprite.call(this, PIXI.TextureCache[key]);
95-
96-
if (this.game.cache.isSpriteSheet(key))
97-
{
98-
this.animations.loadFrameData(this.game.cache.getFrameData(key));
99-
100-
if (frame !== null)
101-
{
102-
if (typeof frame === 'string')
103-
{
104-
this.frameName = frame;
105-
}
106-
else
107-
{
108-
this.frame = frame;
109-
}
110-
}
111-
}
112-
else
113-
{
114-
this.currentFrame = this.game.cache.getFrame(key);
115-
}
116-
}
117-
118-
// this.loadTexture(key, frame);
119-
120-
/**
121-
* The rectangular area from the texture that will be rendered.
122-
* @property {Phaser.Rectangle} textureRegion
123-
*/
124-
// this.textureRegion = new Phaser.Rectangle(this.texture.frame.x, this.texture.frame.y, this.texture.frame.width, this.texture.frame.height);
65+
this.loadTexture(key, frame);
12566

12667
this.position.x = x;
12768
this.position.y = y;
@@ -142,17 +83,13 @@ Phaser.Image = function (game, x, y, key, frame) {
14283
this.autoCull = false;
14384

14485
/**
145-
* A Sprite that is fixed to the camera ignores the position of any ancestors in the display list and uses its x/y coordinates as offsets from the top left of the camera.
86+
* A Sprite that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera.
87+
* Note that if this Image is a child of a display object that has changed its position then the offset will be calculated from that.
14688
* @property {boolean} fixedToCamera - Fixes this Sprite to the Camera.
14789
* @default
14890
*/
14991
this.fixedToCamera = false;
15092

151-
/**
152-
* @property {Phaser.Point} cameraOffset - If this Sprite is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered.
153-
*/
154-
// this.cameraOffset = new Phaser.Point(x, y);
155-
15693
};
15794

15895
Phaser.Image.prototype = Object.create(PIXI.Sprite.prototype);
@@ -182,59 +119,49 @@ Phaser.Image.prototype.preUpdate = function() {
182119
};
183120

184121
/**
185-
* Checks if the Image bounds are within the game world, otherwise false if fully outside of it.
122+
* Internal function called by the World postUpdate cycle.
186123
*
187-
* @method Phaser.Image#inWorld
124+
* @method Phaser.Image#postUpdate
188125
* @memberof Phaser.Image
189-
* @return {boolean} True if the Image bounds is within the game world, otherwise false if fully outside of it.
190126
*/
191-
Phaser.Image.prototype.inWorld = function() {
127+
Phaser.Image.prototype.postUpdate = function() {
192128

193-
return this.game.world.bounds.intersects(this.getBounds());
129+
if (this.key instanceof Phaser.BitmapData && this.key._dirty)
130+
{
131+
this.key.render();
132+
}
133+
134+
if (this.fixedToCamera)
135+
{
136+
this.position.x = this.game.camera.view.x + this.x;
137+
this.position.y = this.game.camera.view.y + this.y;
138+
}
194139

195140
};
196141

197142
/**
198-
* Resets the Sprite.crop value back to the frame dimensions.
143+
* Checks if the Image bounds are within the game world, otherwise false if fully outside of it.
199144
*
200-
* @method Phaser.Image#resetCrop
145+
* @method Phaser.Image#inWorld
201146
* @memberof Phaser.Image
202-
Phaser.Image.prototype.resetCrop = function() {
147+
* @return {boolean} True if the Image bounds is within the game world, even if only partially. Otherwise false if fully outside of it.
148+
*/
149+
Phaser.Image.prototype.inWorld = function() {
203150

204-
this.crop = new Phaser.Rectangle(0, 0, this._cache.width, this._cache.height);
205-
this.texture.setFrame(this.crop);
206-
this.cropEnabled = false;
151+
return this.game.world.bounds.intersects(this.getBounds());
207152

208153
};
209-
*/
210154

211155
/**
212-
* Internal function called by the World postUpdate cycle.
156+
* Checks if the Image bounds are within the game camera, otherwise false if fully outside of it.
213157
*
214-
* @method Phaser.Image#postUpdate
158+
* @method Phaser.Image#inCamera
215159
* @memberof Phaser.Image
160+
* @return {boolean} True if the Image bounds is within the game camera, even if only partially. Otherwise false if fully outside of it.
216161
*/
217-
Phaser.Image.prototype.postUpdate = function() {
162+
Phaser.Image.prototype.inCamera = function() {
218163

219-
if (this.key instanceof Phaser.BitmapData && this.key._dirty)
220-
{
221-
this.key.render();
222-
}
223-
224-
if (this.exists)
225-
{
226-
// if (this.body)
227-
// {
228-
// this.body.postUpdate();
229-
// }
230-
231-
if (this.fixedToCamera)
232-
{
233-
this.position.x = this.game.camera.view.x + this.cameraOffset.x;
234-
this.position.y = this.game.camera.view.y + this.cameraOffset.y;
235-
}
236-
237-
}
164+
return this.game.world.camera.screenView.intersects(this.getBounds());
238165

239166
};
240167

@@ -270,11 +197,16 @@ Phaser.Image.prototype.loadTexture = function (key, frame) {
270197
}
271198
else
272199
{
273-
if (typeof key === 'undefined' || this.game.cache.checkImageKey(key) === false)
200+
if (key === null || typeof key === 'undefined')
274201
{
275202
key = '__default';
276203
this.key = key;
277204
}
205+
else if (typeof key === 'string' && this.game.cache.checkImageKey(key) === false)
206+
{
207+
key = '__missing';
208+
this.key = key;
209+
}
278210

279211
if (this.game.cache.isSpriteSheet(key))
280212
{
@@ -307,31 +239,19 @@ Phaser.Image.prototype.loadTexture = function (key, frame) {
307239
};
308240

309241
/**
310-
* Moves the sprite so its center is located on the given x and y coordinates.
311-
* Doesn't change the anchor point of the sprite.
312-
*
313-
* @method Phaser.Image#centerOn
242+
* Crop allows you to crop the texture used to display this Image. Cropping takes place from the top-left of the Image and can be modified in real-time.
243+
*
244+
* @method Phaser.Image#crop
314245
* @memberof Phaser.Image
315-
* @param {number} x - The x coordinate (in world space) to position the Sprite at.
316-
* @param {number} y - The y coordinate (in world space) to position the Sprite at.
317-
* @return (Phaser.Image) This instance.
318-
Phaser.Image.prototype.centerOn = function(x, y) {
319-
320-
if (this.fixedToCamera)
321-
{
322-
this.cameraOffset.x = x + (this.cameraOffset.x - this.center.x);
323-
this.cameraOffset.y = y + (this.cameraOffset.y - this.center.y);
324-
}
325-
else
326-
{
327-
this.x = x + (this.x - this.center.x);
328-
this.y = y + (this.y - this.center.y);
329-
}
246+
* @param {number} frame - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
247+
*/
248+
Phaser.Image.prototype.crop = function(x, y, width, height) {
330249

331-
return this;
250+
// this.crop = new Phaser.Rectangle(0, 0, this._cache.width, this._cache.height);
251+
// this.texture.setFrame(this.crop);
252+
// this.cropEnabled = false;
332253

333254
};
334-
*/
335255

336256
/**
337257
* Brings a 'dead' Sprite back to life, optionally giving it the health value specified.
@@ -340,7 +260,7 @@ Phaser.Image.prototype.centerOn = function(x, y) {
340260
*
341261
* @method Phaser.Image#revive
342262
* @memberof Phaser.Image
343-
* @return (Phaser.Image) This instance.
263+
* @return {Phaser.Image} This instance.
344264
*/
345265
Phaser.Image.prototype.revive = function() {
346266

@@ -365,7 +285,7 @@ Phaser.Image.prototype.revive = function() {
365285
*
366286
* @method Phaser.Image#kill
367287
* @memberof Phaser.Image
368-
* @return (Phaser.Image) This instance.
288+
* @return {Phaser.Image} This instance.
369289
*/
370290
Phaser.Image.prototype.kill = function() {
371291

@@ -423,7 +343,7 @@ Phaser.Image.prototype.destroy = function() {
423343
* @memberof Phaser.Image
424344
* @param {number} x - The x coordinate (in world space) to position the Sprite at.
425345
* @param {number} y - The y coordinate (in world space) to position the Sprite at.
426-
* @return (Phaser.Image) This instance.
346+
* @return {Phaser.Image} This instance.
427347
*/
428348
Phaser.Image.prototype.reset = function(x, y) {
429349

@@ -446,7 +366,7 @@ Phaser.Image.prototype.reset = function(x, y) {
446366
*
447367
* @method Phaser.Image#bringToTop
448368
* @memberof Phaser.Image
449-
* @return (Phaser.Image) This instance.
369+
* @return {Phaser.Image} This instance.
450370
*/
451371
Phaser.Image.prototype.bringToTop = function(child) {
452372

@@ -469,32 +389,24 @@ Phaser.Image.prototype.bringToTop = function(child) {
469389
/**
470390
* Indicates the rotation of the Sprite, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation.
471391
* Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement player.angle = 450 is the same as player.angle = 90.
472-
* If you wish to work in radians instead of degrees use the property Sprite.rotation instead.
473-
* @name Phaser.Image#angle
474-
* @property {number} angle - Gets or sets the Sprites angle of rotation in degrees.
392+
* If you wish to work in radians instead of degrees use the property Sprite.rotation instead. Working in radians is also computationally faster.
393+
*
394+
* @method Phaser.Image#angle
395+
* @memberof Phaser.Image
396+
* @param {number} [value] - If given it will set the Images angle to this value. Value should be given in degrees.
397+
* @return {number} The angle of this Image in degrees.
475398
*/
476-
Object.defineProperty(Phaser.Image.prototype, 'angle', {
399+
Phaser.Image.prototype.angle = function(value) {
477400

478-
get: function() {
401+
if (typeof value === 'undefined')
402+
{
479403
return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation));
480-
},
481-
482-
set: function(value) {
483-
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
484404
}
405+
else
406+
{
407+
this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value));
485408

486-
});
487-
488-
/**
489-
* @name Phaser.Image#inCamera
490-
* @property {boolean} inCamera - Is this sprite visible to the camera or not?
491-
* @readonly
492-
*/
493-
Object.defineProperty(Phaser.Image.prototype, "inCamera", {
494-
495-
get: function () {
496-
return this._cache.cameraVisible;
409+
return Phaser.Math.radToDeg(this.rotation);
497410
}
498411

499-
});
500-
412+
};

0 commit comments

Comments
 (0)