Skip to content

Commit ed51aff

Browse files
authored
Merge branch 'master' into feature-multi-image-loader
2 parents 674254e + cf8e2cf commit ed51aff

60 files changed

Lines changed: 2132 additions & 978 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,43 @@
66

77
* The Phaser 3 Labs has gained a nifty 'search' feature box thanks to @NemoStein - it allows you to filter out the example categories.
88
* We've added a Mask component, which is available on nearly all Game Objects. It includes the methods `setMask`, `clearMask`, `createBitmapMask` and `createGeometryMask`.
9+
* CanvasTexture is a new extension of the Texture object specifically created for when you've got a Canvas element as the backing source of the texture that you wish to draw to programmatically using the Canvas API. This was possible in previous versions, as a Texture object supported having a Canvas as its source, but we've streamlined the process and made it a lot easier for you to refresh the resulting WebGLTexture on the GPU. To create a CanvasTexture just call the `TextureManager.createCanvas` method as before, only this time you'll get a CanvasTexture back which has helper properties and methods. See the complete JSDocs for more details.
910

1011
### Updates
1112

1213
* If you're using Webpack with Phaser you'll need to update your config to match our new one.
1314
* We've swapped use of the Webpack DefinePlugin so instead of setting a global flag for the compilation of the Canvas and WebGL renderers, we now use a typeof check instead. This means you should now be able to ingest the Phaser source more easily outside of Webpack without having to define any global vars first (thanks @tgrajewski)
1415
* Under Webpack we still use the raw-loader to import our shader source, but outside of Webpack we now use `require.extensions` to load the shader source via fs. This should allow you to bundle Phaser with packages other than Webpack more easily (thanks @tgrajewski)
15-
* The Texture Manager will now emit an `addtexture` event whenever you add a new texture to it, which includes when you load images files from the Loader (as it automatically populates the Texture Manager). Once you receive an `addtexture` event you know the image is loaded and the texture is safe to be applied to a Game Object.
16+
* The Texture Manager will now emit an `addtexture` event whenever you add a new texture to it, which includes when you load image files from the Loader (as it automatically populates the Texture Manager). Once you receive an `addtexture` event you know the image is loaded and the texture is safe to be applied to a Game Object.
17+
* BitmapMask and GeometryMask both have new `destroy` methods which clear their references, freeing them for gc.
18+
* CanvasPool has a new argument `selfParent` which allows the canvas itself to be the parent key, used for later removal.
19+
* Frame has a new method `setSize` which allows you to set the frame x, y, width and height and have it update all of the internal properties automatically. This is now called directly in the constructor.
20+
* When a TextureSource is destroyed if it's got a canvas texture it's removed from the CanvasPool.
21+
* TextureManager.checkKey will check if a texture key is in-use and log a console error if it is and then return a boolean. This is now used extensively internally to prevent you from adding textures that already exist into the manager. If you wish to just check if a key is in use without the error, use the `TextureManager.exists` method as before.
22+
* TextureManager.remove will allow you to remove a texture from the manager. The texture is destroyed and it emits a `removetexture` event.
23+
* TextureSource has a new property `renderer` as it's used a lot internally and is useful if you extend the class.
24+
* TextureSource will now remove its respective WebGLTexture from the renderer when destroyed.
25+
* TextureSource will now automatically create a glTexture from its canvas if using one.
26+
* WebGLRenderer will now remove a GL texture from its local `nativeTextures` array when you call the `deleteTexture` method.
27+
* The BaseCache has a new method `exists` that will return a boolean if an entry for the given key exists in the cache or not.
28+
* Loader.File has a new argument in its constructor which is an instance of the LoaderPlugin. It stores this in the `loader` property. It also has a new property `cache` which is a reference to the cache that the file type will be stored in.
29+
* Loader.File has a new method `hasCacheConflict` which checks if a key matching the one used by this file exists in the target Cache or not.
30+
* Loader.File has a new method `addToCache` which will add the file to its target cache and then emit a `filecomplete` event, passing its key and a reference to itself to the listener (thanks to @kalebwalton for a related PR)
31+
* LoaderPlugin has a new property `cacheManager` which is a reference to the global game cache and is used by the File Types.
32+
* LoaderPlugin has a new property `textureManager` which is a reference to the global Texture Manager and is used by the File Types.
33+
* LoaderPlugin will now check to see if loading a file would cache a cache conflict or not, and prevent it if it will.
34+
* LoaderPlugin now passes off processing of the final file data to the file itself, which will now self-add itself to its target cache.
1635

1736
### Bug Fixes
1837

1938
* DataManagerPlugin would throw an error on Game.destroy if you had any Scenes in the Scene Manager had not been run. Fix #3596 (thanks @kuoruan)
39+
* If you created a Game with no Scenes defined, and then added one via `Game.scene.add` and passed in a data object, the data would be ignored when starting the Scene.
2040

2141
### Examples, Documentation and TypeScript
2242

2343
My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs:
2444

25-
@wtravO
45+
@wtravO @Fabadiculous @zilbuz @samme
2646

2747
## Version 3.6.0 - Asuna - 19th April 2018
2848

src/cache/BaseCache.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ var BaseCache = new Class({
8383

8484
/**
8585
* Checks if this cache contains an item matching the given key.
86+
* This performs the same action as `BaseCache.exists`.
8687
*
8788
* @method Phaser.Cache.BaseCache#has
8889
* @since 3.0.0
@@ -96,6 +97,22 @@ var BaseCache = new Class({
9697
return this.entries.has(key);
9798
},
9899

100+
/**
101+
* Checks if this cache contains an item matching the given key.
102+
* This performs the same action as `BaseCache.has` and is called directly by the Loader.
103+
*
104+
* @method Phaser.Cache.BaseCache#exists
105+
* @since 3.7.0
106+
*
107+
* @param {string} key - The unique key of the item to be checked in this cache.
108+
*
109+
* @return {boolean} Returns `true` if the cache contains an item matching the given key, otherwise `false`.
110+
*/
111+
exists: function (key)
112+
{
113+
return this.entries.has(key);
114+
},
115+
99116
/**
100117
* Gets an item from this cache based on the given key.
101118
*

src/display/canvas/CanvasPool.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ var CanvasPool = function ()
3636
* @param {integer} [width=1] - The width of the Canvas.
3737
* @param {integer} [height=1] - The height of the Canvas.
3838
* @param {integer} [canvasType=Phaser.CANVAS] - The type of the Canvas. Either `Phaser.CANVAS` or `Phaser.WEBGL`.
39+
* @param {boolean} [selfParent=false] - Use the generated Canvas element as the parent?
3940
*
4041
* @return {HTMLCanvasElement} [description]
4142
*/
42-
var create = function (parent, width, height, canvasType)
43+
var create = function (parent, width, height, canvasType, selfParent)
4344
{
4445
if (width === undefined) { width = 1; }
4546
if (height === undefined) { height = 1; }
4647
if (canvasType === undefined) { canvasType = CONST.CANVAS; }
48+
if (selfParent === undefined) { selfParent = false; }
4749

4850
var canvas;
4951
var container = first(canvasType);
@@ -70,6 +72,11 @@ var CanvasPool = function ()
7072
canvas = container.canvas;
7173
}
7274

75+
if (selfParent)
76+
{
77+
container.parent = canvas;
78+
}
79+
7380
canvas.width = width;
7481
canvas.height = height;
7582

src/display/mask/BitmapMask.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,24 @@ var BitmapMask = new Class({
191191
postRenderCanvas: function ()
192192
{
193193
// NOOP
194+
},
195+
196+
/**
197+
* Destroys this BitmapMask and nulls any references it holds.
198+
*
199+
* Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it,
200+
* so be sure to call `clearMask` on any Game Object using it, before destroying it.
201+
*
202+
* @method Phaser.Display.Masks.BitmapMask#destroy
203+
* @since 3.6.1
204+
*/
205+
destroy: function ()
206+
{
207+
this.bitmapMask = null;
208+
this.mainTexture = null;
209+
this.maskTexture = null;
210+
this.mainFramebuffer = null;
211+
this.maskFramebuffer = null;
194212
}
195213

196214
});

src/display/mask/GeometryMask.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ var GeometryMask = new Class({
131131
postRenderCanvas: function (renderer)
132132
{
133133
renderer.currentContext.restore();
134+
},
135+
136+
/**
137+
* Destroys this GeometryMask and nulls any references it holds.
138+
*
139+
* Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it,
140+
* so be sure to call `clearMask` on any Game Object using it, before destroying it.
141+
*
142+
* @method Phaser.Display.Masks.GeometryMask#destroy
143+
* @since 3.6.1
144+
*/
145+
destroy: function ()
146+
{
147+
this.geometryMask = null;
134148
}
135149

136150
});

src/gameobjects/components/GetBounds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ var GetBounds = {
196196
* @method Phaser.GameObjects.Components.GetBounds#getBounds
197197
* @since 3.0.0
198198
*
199-
* @generic {Phaser.Math.Vector2} O - [output,$return]
199+
* @generic {Phaser.Geom.Rectangle} O - [output,$return]
200200
*
201201
* @param {(Phaser.Geom.Rectangle|object)} [output] - An object to store the values in. If not provided a new Rectangle will be created.
202202
*

src/gameobjects/components/Mask.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,19 @@ var Mask = {
5555
* @method Phaser.GameObjects.Components.Mask#clearMask
5656
* @since 3.6.2
5757
*
58+
* @param {boolean} [destroyMask=false] - Destroy the mask before clearing it?
59+
*
5860
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
5961
*/
60-
clearMask: function ()
62+
clearMask: function (destroyMask)
6163
{
64+
if (destroyMask === undefined) { destroyMask = false; }
65+
66+
if (destroyMask)
67+
{
68+
this.mask.destroy();
69+
}
70+
6271
this.mask = null;
6372

6473
return this;

src/gameobjects/components/Texture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var Texture = {
2020
* The Texture this Game Object is using to render with.
2121
*
2222
* @name Phaser.GameObjects.Components.Texture#texture
23-
* @type {Phaser.Textures.Texture}
23+
* @type {Phaser.Textures.Texture|Phaser.Textures.CanvasTexture}
2424
* @since 3.0.0
2525
*/
2626
texture: null,

src/gameobjects/graphics/Graphics.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ var Graphics = new Class({
11391139

11401140
if (sys.game.renderer.gl && texture)
11411141
{
1142-
texture.source[0].glTexture = sys.game.renderer.canvasToTexture(ctx.canvas, texture.source[0].glTexture, true, 0);
1142+
texture.source[0].glTexture = sys.game.renderer.canvasToTexture(ctx.canvas, texture.source[0].glTexture);
11431143
}
11441144
}
11451145

src/gameobjects/particles/EmitterOp.js

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,81 @@ var GetFastValue = require('../../utils/object/GetFastValue');
1111
var Wrap = require('../../math/Wrap');
1212

1313
/**
14-
* The returned value sets what the property will be at the START of the particles life, on emit.
14+
* The returned value sets what the property will be at the START of the particle's life, on emit.
1515
* @callback EmitterOpOnEmitCallback
1616
*
17-
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
18-
* @param {string} key - [description]
19-
* @param {number} value - [description]
17+
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
18+
* @param {string} key - The name of the property.
19+
* @param {number} value - The current value of the property.
2020
*
21-
* @return {number} [description]
21+
* @return {number} The new value of the property.
2222
*/
2323

2424
/**
25-
* The returned value updates the property for the duration of the particles life.
25+
* The returned value updates the property for the duration of the particle's life.
2626
* @callback EmitterOpOnUpdateCallback
2727
*
28-
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
29-
* @param {string} key - [description]
30-
* @param {float} t - The T value (between 0 and 1)
31-
* @param {number} value - [description]
28+
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
29+
* @param {string} key - The name of the property.
30+
* @param {float} t - The normalized lifetime of the particle, between 0 (start) and 1 (end).
31+
* @param {number} value - The current value of the property.
3232
*
33-
* @return {number} [description]
33+
* @return {number} The new value of the property.
34+
*/
35+
36+
/**
37+
* Defines an operation yielding a random value within a range.
38+
* @typedef {object} EmitterOpRandomConfig
39+
*
40+
* @property {float[]} random - The minimum and maximum values, as [min, max].
41+
*/
42+
43+
/**
44+
* Defines an operation yielding a random value within a range.
45+
* @typedef {object} EmitterOpRandomMinMaxConfig
46+
*
47+
* @property {float} min - The minimum value.
48+
* @property {float} max - The maximum value.
49+
*/
50+
51+
/**
52+
* Defines an operation yielding a random value within a range.
53+
* @typedef {object} EmitterOpRandomStartEndConfig
54+
*
55+
* @property {float} start - The starting value.
56+
* @property {float} end - The ending value.
57+
* @property {boolean} random - If false, this becomes {@link EmitterOpEaseConfig}.
58+
*/
59+
60+
/**
61+
* Defines an operation yielding a value incremented continuously across a range.
62+
* @typedef {object} EmitterOpEaseConfig
63+
*
64+
* @property {float} start - The starting value.
65+
* @property {float} end - The ending value.
66+
* @property {string} [ease='Linear'] - The name of the easing function.
67+
*/
68+
69+
/**
70+
* Defines an operation yielding a value incremented by steps across a range.
71+
* @typedef {object} EmitterOpSteppedConfig
72+
*
73+
* @property {number} start - The starting value.
74+
* @property {number} end - The ending value.
75+
* @property {number} steps - The number of steps between start and end.
76+
*/
77+
78+
/**
79+
* @typedef {object} EmitterOpCustomEmitConfig
80+
*
81+
* @property {EmitterOpOnEmitCallback} onEmit - [description]
82+
*/
83+
84+
/**
85+
* @typedef {object} EmitterOpCustomUpdateConfig
86+
*
87+
* @property {EmitterOpOnEmitCallback} [onEmit] - [description]
88+
* @property {EmitterOpOnUpdateCallback} onUpdate - [description]
3489
*/
3590

3691
/**
@@ -48,7 +103,10 @@ var Wrap = require('../../math/Wrap');
48103
* @param {boolean} [emitOnly=false] - [description]
49104
*/
50105
var EmitterOp = new Class({
51-
initialize: function EmitterOp (config, key, defaultValue, emitOnly)
106+
107+
initialize:
108+
109+
function EmitterOp (config, key, defaultValue, emitOnly)
52110
{
53111
if (emitOnly === undefined)
54112
{
@@ -247,7 +305,7 @@ var EmitterOp = new Class({
247305
// x: 400
248306

249307
this.onEmit = this.staticValueEmit;
250-
this.onUpdate = this.staticValueUpdate;
308+
this.onUpdate = this.staticValueUpdate; // How?
251309
}
252310
else if (Array.isArray(value))
253311
{
@@ -277,18 +335,12 @@ var EmitterOp = new Class({
277335
this.onUpdate = value;
278336
}
279337
}
280-
else if (
281-
t === 'object' &&
282-
(this.has(value, 'random') ||
283-
this.hasBoth(value, 'start', 'end') ||
284-
this.hasBoth(value, 'min', 'max'))
285-
)
338+
else if (t === 'object' && (this.has(value, 'random') || this.hasBoth(value, 'start', 'end') || this.hasBoth(value, 'min', 'max')))
286339
{
287340
this.start = this.has(value, 'start') ? value.start : value.min;
288341
this.end = this.has(value, 'end') ? value.end : value.max;
289342

290-
var isRandom =
291-
this.hasBoth(value, 'min', 'max') || this.has(value, 'random');
343+
var isRandom = (this.hasBoth(value, 'min', 'max') || this.has(value, 'random'));
292344

293345
// A random starting value (using 'min | max' instead of 'start | end' automatically implies a random value)
294346

@@ -336,13 +388,13 @@ var EmitterOp = new Class({
336388
this.onEmit = this.easedValueEmit;
337389
}
338390

391+
// BUG: alpha, rotate, scaleX, scaleY, or tint are eased here if {min, max} is given.
392+
// Probably this branch should exclude isRandom entirely.
393+
339394
this.onUpdate = this.easeValueUpdate;
340395
}
341396
}
342-
else if (
343-
t === 'object' &&
344-
this.hasEither(value, 'onEmit', 'onUpdate')
345-
)
397+
else if (t === 'object' && this.hasEither(value, 'onEmit', 'onUpdate'))
346398
{
347399
// Custom onEmit and onUpdate callbacks
348400

0 commit comments

Comments
 (0)