mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 12:43:26 +00:00
Merge branch 'photonstorm:master' into spatial-sound
This commit is contained in:
commit
663fda13c3
16 changed files with 497 additions and 268 deletions
|
@ -387,6 +387,18 @@ emitter.setSortProperty('y', true);
|
|||
* `ParticleEmitter.getWorldTransformMatrix` is a new method that allows a Particle Emitter to calculate its world transform, factoring in any parents.
|
||||
* `ParticleEmitter.worldMatrix` is a new property that holds a TransformMatrix used for bounds calculations.
|
||||
|
||||
#### Particle Emitter Bounds
|
||||
|
||||
* Prior to v3.60 a Particle Emitter had a `bounds` property. This was a Rectangle and if a Particle hit any of its edges it would rebound off it based on the Particles `bounce` value. In v3.60 this action has been moved to a Particle Processor. You can still configure the bounds via the Emitter config using the `bounds` property, as before. And you can configure which faces collide via the `collideLeft` etc properties. However, the following internal changes have taken place:
|
||||
* `ParticleBounds` is a new Particle Processor class that handles updating the particles.
|
||||
* The `ParticleEmitter.setBounds` method has been replaced with `ParticleEmitter.addParticleBounds` which now returns a new `ParticleBounds` Particle Processor instance.
|
||||
* The `ParticleEmitter.bounds` property has been removed. Please see the `addParticleBounds` method if you wish to retain this object.
|
||||
* The `ParticleEmitter.collideLeft` property has been removed. It's now part of the `ParticleBounds` Particle Processor.
|
||||
* The `ParticleEmitter.collideRight` property has been removed. It's now part of the `ParticleBounds` Particle Processor.
|
||||
* The `ParticleEmitter.collideTop` property has been removed. It's now part of the `ParticleBounds` Particle Processor.
|
||||
* The `ParticleEmitter.collideBottom` property has been removed. It's now part of the `ParticleBounds` Particle Processor.
|
||||
* The `Particle.checkBounds` method has been removed as it's now handled by the Particle Processors.
|
||||
|
||||
#### Particle Processors
|
||||
|
||||
* `ParticleProcessor` is a new base class that you can use to create your own Particle Processors, which are special processors capable of manipulating the path of Particles based on your own logic or math. It provides the structure required to handle the processing of particles and should be used as a base for your own classes.
|
||||
|
@ -467,6 +479,7 @@ Another potentially breaking change is the removal of two internal private count
|
|||
|
||||
#### Further Particle System Updates and Fixes:
|
||||
|
||||
* The Particle `DeathZone.willKill` method now takes a `Particle` instance as its only parameter, instead of x and y coordinates, allowing you to perform more complex checks before deciding if the Particle should be killed, or not.
|
||||
* The `Particle.resetPosition` method has been renamed to `setPosition` and it now takes optional x/y parameters. If not given, it performs the same task as `resetPosition` did in earlier versions.
|
||||
* The `ParticleEmitter` class now has the `AlphaSingle` Component. This allows you to call `setAlpha` on the Emitter instance itself and have it impact all particles being rendered by it, allowing you to now 'fade in/out' a whole Emitter.
|
||||
* Setting `frequency` wasn't working correctly in earlier versions. It should allow you to specify a time, in ms, between which each 'quantity' of particles is emitted. However, the `preUpdate` loop was calculating the value incorrectly. It will now count down the right amount of time before emiting another batch of particles.
|
||||
|
@ -882,6 +895,10 @@ The following are API-breaking, in that a new optional parameter has been insert
|
|||
|
||||
### Updates
|
||||
|
||||
* `Texture.has` will now return a strict boolean, rather than an object that can be cooerced into a boolean (thanks @samme)
|
||||
* The `CanvasTexture.draw` method has a new optional parameter `update` which allows you to control if the internal ImageData is recalculated, or not (thanks @samme)
|
||||
* The `CanvasTexture.drawFrame` method has a new optional parameter `update` which allows you to control if the internal ImageData is recalculated, or not (thanks @samme)
|
||||
* The `CanvasTexture.clear` method has a new optional parameter `update` which allows you to control if the internal ImageData is recalculated, or not (thanks @samme)
|
||||
* The `Game.registry`, which is a `DataManager` instance that can be used as a global store of game wide data will now use its own Event Emitter, instead of the Game's Event Emitter. This means it's perfectly safe for you to now use the Registry to emit and listen for your own custom events without conflicting with events the Phaser Game instance emits.
|
||||
* The `GenerateVerts` function has a new optional parameter `flipUV` which, if set, will flip the UV texture coordinates (thanks cedarcantab)
|
||||
* The `GenerateVerts` function no longer errors if the verts and uvs arrays are not the same size and `containsZ` is true (thanks cedarcantab)
|
||||
|
@ -1136,6 +1153,7 @@ My thanks to the following for helping with the Phaser 3 Examples, Beta Testing,
|
|||
@necrokot
|
||||
@Nero0
|
||||
@orjandh
|
||||
@pavle-goloskokovic
|
||||
@PhaserEditor2D
|
||||
@Pythux
|
||||
@quocsinh
|
||||
|
|
|
@ -399,6 +399,13 @@ var Animation = new Class({
|
|||
{
|
||||
textureKey = frames;
|
||||
|
||||
if (!textureManager.exists(textureKey))
|
||||
{
|
||||
console.warn('Texture "%s" not found', textureKey);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
var texture = textureManager.get(textureKey);
|
||||
var frameKeys = texture.getFrameNames();
|
||||
|
||||
|
@ -437,6 +444,13 @@ var Animation = new Class({
|
|||
// The actual texture frame
|
||||
var textureFrame = textureManager.getFrame(key, frame);
|
||||
|
||||
if (!textureFrame)
|
||||
{
|
||||
console.warn('Texture "%s" not found', key);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
animationFrame = new Frame(key, frame, index, textureFrame);
|
||||
|
||||
animationFrame.duration = GetValue(item, 'duration', 0);
|
||||
|
|
|
@ -637,6 +637,13 @@ var AnimationManager = new Class({
|
|||
var out = GetValue(config, 'outputArray', []);
|
||||
var frames = GetValue(config, 'frames', false);
|
||||
|
||||
if (!this.textureManager.exists(key))
|
||||
{
|
||||
console.warn('Texture "%s" not found', key);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
var texture = this.textureManager.get(key);
|
||||
|
||||
if (!texture)
|
||||
|
@ -673,7 +680,7 @@ var AnimationManager = new Class({
|
|||
}
|
||||
else
|
||||
{
|
||||
console.warn('generateFrameNames: Frame missing: ' + frame + ' from texture: ' + key);
|
||||
console.warn('Frame "%s" not found in texture "%s"', frame, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -736,6 +743,13 @@ var AnimationManager = new Class({
|
|||
var out = GetValue(config, 'outputArray', []);
|
||||
var frames = GetValue(config, 'frames', false);
|
||||
|
||||
if (!this.textureManager.exists(key))
|
||||
{
|
||||
console.warn('Texture "%s" not found', key);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
var texture = this.textureManager.get(key);
|
||||
|
||||
if (!texture)
|
||||
|
@ -763,13 +777,15 @@ var AnimationManager = new Class({
|
|||
|
||||
for (var i = 0; i < frames.length; i++)
|
||||
{
|
||||
if (texture.has(frames[i]))
|
||||
var frameName = frames[i];
|
||||
|
||||
if (texture.has(frameName))
|
||||
{
|
||||
out.push({ key: key, frame: frames[i] });
|
||||
out.push({ key: key, frame: frameName });
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('generateFrameNumbers: Frame ' + i + ' missing from texture: ' + key);
|
||||
console.warn('Frame "%s" not found in texture "%s"', frameName, key);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -512,7 +512,6 @@ var Transform = {
|
|||
getWorldTransformMatrix: function (tempMatrix, parentMatrix)
|
||||
{
|
||||
if (tempMatrix === undefined) { tempMatrix = new TransformMatrix(); }
|
||||
if (parentMatrix === undefined) { parentMatrix = new TransformMatrix(); }
|
||||
|
||||
var parent = this.parentContainer;
|
||||
|
||||
|
@ -521,6 +520,11 @@ var Transform = {
|
|||
return this.getLocalTransformMatrix(tempMatrix);
|
||||
}
|
||||
|
||||
if (!parentMatrix)
|
||||
{
|
||||
parentMatrix = new TransformMatrix();
|
||||
}
|
||||
|
||||
tempMatrix.applyITRS(this.x, this.y, this._rotation, this._scaleX, this._scaleY);
|
||||
|
||||
while (parent)
|
||||
|
|
|
@ -154,7 +154,7 @@ var NineSlice = new Class({
|
|||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this._width = width;
|
||||
this._width;
|
||||
|
||||
/**
|
||||
* Internal height value. Do not modify this property directly.
|
||||
|
@ -164,7 +164,7 @@ var NineSlice = new Class({
|
|||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this._height = height;
|
||||
this._height;
|
||||
|
||||
/**
|
||||
* Internal originX value. Do not modify this property directly.
|
||||
|
@ -226,51 +226,47 @@ var NineSlice = new Class({
|
|||
/**
|
||||
* The size of the left vertical bar (A).
|
||||
*
|
||||
* You should treat this property as read-only.
|
||||
*
|
||||
* @name Phaser.GameObjects.NineSlice#leftWidth
|
||||
* @type {number}
|
||||
* @readonly
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.leftWidth = leftWidth;
|
||||
this.leftWidth;
|
||||
|
||||
/**
|
||||
* The size of the right vertical bar (B).
|
||||
*
|
||||
* You should treat this property as read-only.
|
||||
*
|
||||
* @name Phaser.GameObjects.NineSlice#rightWidth
|
||||
* @type {number}
|
||||
* @readonly
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.rightWidth = rightWidth;
|
||||
this.rightWidth;
|
||||
|
||||
/**
|
||||
* The size of the top horizontal bar (C).
|
||||
*
|
||||
* You should treat this property as read-only.
|
||||
*
|
||||
* If this is a 3 slice object this property will be set to the
|
||||
* height of the texture being used.
|
||||
*
|
||||
* @name Phaser.GameObjects.NineSlice#topHeight
|
||||
* @type {number}
|
||||
* @readonly
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.topHeight = topHeight;
|
||||
this.topHeight;
|
||||
|
||||
/**
|
||||
* The size of the bottom horizontal bar (D).
|
||||
*
|
||||
* You should treat this property as read-only.
|
||||
*
|
||||
* If this is a 3 slice object this property will be set to zero.
|
||||
*
|
||||
* @name Phaser.GameObjects.NineSlice#bottomHeight
|
||||
* @type {number}
|
||||
* @readonly
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.bottomHeight = bottomHeight;
|
||||
this.bottomHeight;
|
||||
|
||||
/**
|
||||
* The tint value being applied to the top-left vertice of the Game Object.
|
||||
|
@ -316,23 +312,76 @@ var NineSlice = new Class({
|
|||
}
|
||||
|
||||
this.setPosition(x, y);
|
||||
|
||||
this.setTexture(texture, frame);
|
||||
|
||||
if (this.is3Slice)
|
||||
{
|
||||
height = this.frame.height;
|
||||
|
||||
this._height = height;
|
||||
this.topHeight = height;
|
||||
this.bottomHeight = 0;
|
||||
}
|
||||
|
||||
this.updateVertices();
|
||||
this.updateUVs();
|
||||
this.setSlices(width, height, leftWidth, rightWidth, topHeight, bottomHeight);
|
||||
|
||||
this.initPipeline();
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets the width, height and slices for this NineSlice Game Object.
|
||||
*
|
||||
* This allows you to modify the texture being used by this object and then reset the slice configuration,
|
||||
* to avoid having to destroy this Game Object in order to use it for a different game element.
|
||||
*
|
||||
* Please note that you cannot change a 9-slice to a 3-slice or vice versa.
|
||||
*
|
||||
* @method Phaser.GameObjects.NineSlice#setSlices
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} [width=256] - The width of the Nine Slice Game Object. You can adjust the width post-creation.
|
||||
* @param {number} [height=256] - The height of the Nine Slice Game Object. If this is a 3 slice object the height will be fixed to the height of the texture and cannot be changed.
|
||||
* @param {number} [leftWidth=10] - The size of the left vertical column (A).
|
||||
* @param {number} [rightWidth=10] - The size of the right vertical column (B).
|
||||
* @param {number} [topHeight=0] - The size of the top horiztonal row (C). Set to zero or undefined to create a 3 slice object.
|
||||
* @param {number} [bottomHeight=0] - The size of the bottom horiztonal row (D). Set to zero or undefined to create a 3 slice object.
|
||||
*
|
||||
* @return {this} This Game Object instance.
|
||||
*/
|
||||
setSlices: function (width, height, leftWidth, rightWidth, topHeight, bottomHeight)
|
||||
{
|
||||
if (width === undefined) { width = 256; }
|
||||
if (height === undefined) { height = 256; }
|
||||
|
||||
if (leftWidth === undefined) { leftWidth = 10; }
|
||||
if (rightWidth === undefined) { rightWidth = 10; }
|
||||
if (topHeight === undefined) { topHeight = 0; }
|
||||
if (bottomHeight === undefined) { bottomHeight = 0; }
|
||||
|
||||
var is3Slice = (topHeight === 0 && bottomHeight === 0);
|
||||
|
||||
if (this.is3Slice !== is3Slice)
|
||||
{
|
||||
console.warn('Cannot change 9 slice to 3 slice');
|
||||
}
|
||||
else
|
||||
{
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
|
||||
this.leftWidth = leftWidth;
|
||||
this.rightWidth = rightWidth;
|
||||
this.topHeight = topHeight;
|
||||
this.bottomHeight = bottomHeight;
|
||||
|
||||
if (this.is3Slice)
|
||||
{
|
||||
height = this.frame.height;
|
||||
|
||||
this._height = height;
|
||||
this.topHeight = height;
|
||||
this.bottomHeight = 0;
|
||||
}
|
||||
|
||||
this.updateVertices();
|
||||
this.updateUVs();
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates all of the vertice UV coordinates. This is called automatically
|
||||
* when the NineSlice Game Object is created, or if the texture frame changes.
|
||||
|
@ -340,7 +389,7 @@ var NineSlice = new Class({
|
|||
* Unlike with the `updateVertice` method, you do not need to call this
|
||||
* method if the Nine Slice changes size. Only if it changes texture frame.
|
||||
*
|
||||
* @method Phaser.GameObjects.Mesh#updateUVs
|
||||
* @method Phaser.GameObjects.NineSlice#updateUVs
|
||||
* @since 3.60.0
|
||||
*/
|
||||
updateUVs: function ()
|
||||
|
@ -860,6 +909,15 @@ var NineSlice = new Class({
|
|||
*/
|
||||
setSizeToFrame: function ()
|
||||
{
|
||||
if (this.is3Slice)
|
||||
{
|
||||
var height = this.frame.height;
|
||||
|
||||
this._height = height;
|
||||
this.topHeight = height;
|
||||
this.bottomHeight = 0;
|
||||
}
|
||||
|
||||
this.updateUVs();
|
||||
|
||||
return this;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
var AnimationState = require('../../animations/AnimationState');
|
||||
var Clamp = require('../../math/Clamp');
|
||||
var Class = require('../../utils/Class');
|
||||
var DegToRad = require('../../math/DegToRad');
|
||||
var Rectangle = require('../../geom/rectangle/Rectangle');
|
||||
|
@ -82,6 +83,17 @@ var Particle = new Class({
|
|||
*/
|
||||
this.y = 0;
|
||||
|
||||
/**
|
||||
* The coordinates of this Particle in world space.
|
||||
*
|
||||
* Updated as part of `computeVelocity`.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.Particle#worldPosition
|
||||
* @type {Phaser.Math.Vector2}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.worldPosition = new Vector2();
|
||||
|
||||
/**
|
||||
* The x velocity of this Particle.
|
||||
*
|
||||
|
@ -480,6 +492,8 @@ var Particle = new Class({
|
|||
|
||||
this.rotation = DegToRad(this.angle);
|
||||
|
||||
emitter.worldMatrix.transformPoint(this.x, this.y, this.worldPosition);
|
||||
|
||||
// Check we didn't spawn in the middle of a DeathZone
|
||||
if (this.delayCurrent === 0 && emitter.getDeathZone(this))
|
||||
{
|
||||
|
@ -538,110 +552,6 @@ var Particle = new Class({
|
|||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal method that calculates the velocity of the Particle.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.Particle#computeVelocity
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter that is updating this Particle.
|
||||
* @param {number} delta - The delta time in ms.
|
||||
* @param {number} step - The delta value divided by 1000.
|
||||
* @param {Phaser.GameObjects.Particles.ParticleProcessor[]} processors - An array of all active Particle Processors.
|
||||
* @param {number} t - The current normalized lifetime of the particle, between 0 (birth) and 1 (death).
|
||||
*/
|
||||
computeVelocity: function (emitter, delta, step, processors, t)
|
||||
{
|
||||
var ops = emitter.ops;
|
||||
|
||||
var vx = this.velocityX;
|
||||
var vy = this.velocityY;
|
||||
|
||||
var ax = ops.accelerationX.onUpdate(this, 'accelerationX', t, this.accelerationX);
|
||||
var ay = ops.accelerationY.onUpdate(this, 'accelerationY', t, this.accelerationY);
|
||||
|
||||
var mx = ops.maxVelocityX.onUpdate(this, 'maxVelocityX', t, this.maxVelocityX);
|
||||
var my = ops.maxVelocityY.onUpdate(this, 'maxVelocityY', t, this.maxVelocityY);
|
||||
|
||||
vx += (emitter.gravityX * step);
|
||||
vy += (emitter.gravityY * step);
|
||||
|
||||
if (ax)
|
||||
{
|
||||
vx += (ax * step);
|
||||
}
|
||||
|
||||
if (ay)
|
||||
{
|
||||
vy += (ay * step);
|
||||
}
|
||||
|
||||
if (vx > mx)
|
||||
{
|
||||
vx = mx;
|
||||
}
|
||||
else if (vx < -mx)
|
||||
{
|
||||
vx = -mx;
|
||||
}
|
||||
|
||||
if (vy > my)
|
||||
{
|
||||
vy = my;
|
||||
}
|
||||
else if (vy < -my)
|
||||
{
|
||||
vy = -my;
|
||||
}
|
||||
|
||||
this.velocityX = vx;
|
||||
this.velocityY = vy;
|
||||
|
||||
// Apply any additional processors
|
||||
for (var i = 0; i < processors.length; i++)
|
||||
{
|
||||
processors[i].update(this, delta, step, t);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if this Particle is still within the bounds defined by the given Emitter.
|
||||
*
|
||||
* If not, and depending on the Emitter collision flags, the Particle may either stop or rebound.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.Particle#checkBounds
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter to check the bounds against.
|
||||
*/
|
||||
checkBounds: function (emitter)
|
||||
{
|
||||
var bounds = emitter.bounds;
|
||||
var bounce = -this.bounce;
|
||||
|
||||
if (this.x < bounds.x && emitter.collideLeft)
|
||||
{
|
||||
this.x = bounds.x;
|
||||
this.velocityX *= bounce;
|
||||
}
|
||||
else if (this.x > bounds.right && emitter.collideRight)
|
||||
{
|
||||
this.x = bounds.right;
|
||||
this.velocityX *= bounce;
|
||||
}
|
||||
|
||||
if (this.y < bounds.y && emitter.collideTop)
|
||||
{
|
||||
this.y = bounds.y;
|
||||
this.velocityY *= bounce;
|
||||
}
|
||||
else if (this.y > bounds.bottom && emitter.collideBottom)
|
||||
{
|
||||
this.y = bounds.bottom;
|
||||
this.velocityY *= bounce;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The main update method for this Particle.
|
||||
*
|
||||
|
@ -705,16 +615,6 @@ var Particle = new Class({
|
|||
|
||||
this.computeVelocity(emitter, delta, step, processors, t);
|
||||
|
||||
this.x += this.velocityX * step;
|
||||
this.y += this.velocityY * step;
|
||||
|
||||
if (emitter.bounds)
|
||||
{
|
||||
this.bounce = ops.bounce.onUpdate(this, 'bounce', t, this.bounce);
|
||||
|
||||
this.checkBounds(emitter);
|
||||
}
|
||||
|
||||
this.scaleX = ops.scaleX.onUpdate(this, 'scaleX', t, this.scaleX);
|
||||
this.scaleY = this.scaleX;
|
||||
|
||||
|
@ -751,6 +651,62 @@ var Particle = new Class({
|
|||
return (this.lifeCurrent <= 0 && this.holdCurrent <= 0);
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal method that calculates the velocity of the Particle and
|
||||
* its world position. It also runs it against any active Processors
|
||||
* that are set on the Emitter.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.Particle#computeVelocity
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter that is updating this Particle.
|
||||
* @param {number} delta - The delta time in ms.
|
||||
* @param {number} step - The delta value divided by 1000.
|
||||
* @param {Phaser.GameObjects.Particles.ParticleProcessor[]} processors - An array of all active Particle Processors.
|
||||
* @param {number} t - The current normalized lifetime of the particle, between 0 (birth) and 1 (death).
|
||||
*/
|
||||
computeVelocity: function (emitter, delta, step, processors, t)
|
||||
{
|
||||
var ops = emitter.ops;
|
||||
|
||||
var vx = this.velocityX;
|
||||
var vy = this.velocityY;
|
||||
|
||||
var ax = ops.accelerationX.onUpdate(this, 'accelerationX', t, this.accelerationX);
|
||||
var ay = ops.accelerationY.onUpdate(this, 'accelerationY', t, this.accelerationY);
|
||||
|
||||
var mx = ops.maxVelocityX.onUpdate(this, 'maxVelocityX', t, this.maxVelocityX);
|
||||
var my = ops.maxVelocityY.onUpdate(this, 'maxVelocityY', t, this.maxVelocityY);
|
||||
|
||||
this.bounce = ops.bounce.onUpdate(this, 'bounce', t, this.bounce);
|
||||
|
||||
vx += (emitter.gravityX * step) + (ax * step);
|
||||
vy += (emitter.gravityY * step) + (ay * step);
|
||||
|
||||
vx = Clamp(vx, -mx, mx);
|
||||
vy = Clamp(vy, -my, my);
|
||||
|
||||
this.velocityX = vx;
|
||||
this.velocityY = vy;
|
||||
|
||||
// Integrate back in to the position
|
||||
this.x += vx * step;
|
||||
this.y += vy * step;
|
||||
|
||||
emitter.worldMatrix.transformPoint(this.x, this.y, this.worldPosition);
|
||||
|
||||
// Apply any additional processors (these can update velocity and/or position)
|
||||
for (var i = 0; i < processors.length; i++)
|
||||
{
|
||||
var processor = processors[i];
|
||||
|
||||
if (processor.active)
|
||||
{
|
||||
processor.update(this, delta, step, t);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* This is a NOOP method and does nothing when called.
|
||||
*
|
||||
|
|
148
src/gameobjects/particles/ParticleBounds.js
Normal file
148
src/gameobjects/particles/ParticleBounds.js
Normal file
|
@ -0,0 +1,148 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013-2023 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var Class = require('../../utils/Class');
|
||||
var ParticleProcessor = require('./ParticleProcessor');
|
||||
var Rectangle = require('../../geom/rectangle/Rectangle');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* The Particle Bounds Processor.
|
||||
*
|
||||
* Defines a rectangular region, in world space, within which particle movement
|
||||
* is restrained.
|
||||
*
|
||||
* Use the properties `collideLeft`, `collideRight`, `collideTop` and
|
||||
* `collideBottom` to control if a particle will rebound off the sides
|
||||
* of this boundary, or not.
|
||||
*
|
||||
* This happens when the particles worldPosition x/y coordinate hits the boundary.
|
||||
*
|
||||
* The strength of the rebound is determined by the `Particle.bounce` property.
|
||||
*
|
||||
* @class ParticleBounds
|
||||
* @extends Phaser.GameObjects.Particles.ParticleProcessor
|
||||
* @memberof Phaser.GameObjects.Particles
|
||||
* @constructor
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} x - The x position (top-left) of the bounds, in world space.
|
||||
* @param {number} y - The y position (top-left) of the bounds, in world space.
|
||||
* @param {number} width - The width of the bounds.
|
||||
* @param {number} height - The height of the bounds.
|
||||
* @param {boolean} [collideLeft=true] - Whether particles interact with the left edge of the bounds.
|
||||
* @param {boolean} [collideRight=true] - Whether particles interact with the right edge of the bounds.
|
||||
* @param {boolean} [collideTop=true] - Whether particles interact with the top edge of the bounds.
|
||||
* @param {boolean} [collideBottom=true] - Whether particles interact with the bottom edge of the bounds.
|
||||
*/
|
||||
var ParticleBounds = new Class({
|
||||
|
||||
Extends: ParticleProcessor,
|
||||
|
||||
initialize:
|
||||
|
||||
function ParticleBounds (x, y, width, height, collideLeft, collideRight, collideTop, collideBottom)
|
||||
{
|
||||
if (collideLeft === undefined) { collideLeft = true; }
|
||||
if (collideRight === undefined) { collideRight = true; }
|
||||
if (collideTop === undefined) { collideTop = true; }
|
||||
if (collideBottom === undefined) { collideBottom = true; }
|
||||
|
||||
ParticleProcessor.call(this, x, y, true);
|
||||
|
||||
/**
|
||||
* A rectangular boundary constraining particle movement. Use the Emitter properties `collideLeft`,
|
||||
* `collideRight`, `collideTop` and `collideBottom` to control if a particle will rebound off
|
||||
* the sides of this boundary, or not. This happens when the particles x/y coordinate hits
|
||||
* the boundary.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleBounds#bounds
|
||||
* @type {Phaser.Geom.Rectangle}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.bounds = new Rectangle(x, y, width, height);
|
||||
|
||||
/**
|
||||
* Whether particles interact with the left edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleBounds#collideLeft
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.collideLeft = collideLeft;
|
||||
|
||||
/**
|
||||
* Whether particles interact with the right edge of the emitter {@link Phaser.GameObjects.Particles.ParticleBounds#bounds}.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleBounds#collideRight
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.collideRight = collideRight;
|
||||
|
||||
/**
|
||||
* Whether particles interact with the top edge of the emitter {@link Phaser.GameObjects.Particles.ParticleBounds#bounds}.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleBounds#collideTop
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.collideTop = collideTop;
|
||||
|
||||
/**
|
||||
* Whether particles interact with the bottom edge of the emitter {@link Phaser.GameObjects.Particles.ParticleBounds#bounds}.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleBounds#collideBottom
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.collideBottom = collideBottom;
|
||||
},
|
||||
|
||||
/**
|
||||
* Takes a Particle and updates it against the bounds.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleBounds#update
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.Particles.Particle} particle - The Particle to update.
|
||||
*/
|
||||
update: function (particle)
|
||||
{
|
||||
var bounds = this.bounds;
|
||||
var bounce = -particle.bounce;
|
||||
var pos = particle.worldPosition;
|
||||
|
||||
if (pos.x < bounds.x && this.collideLeft)
|
||||
{
|
||||
particle.x += bounds.x - pos.x;
|
||||
particle.velocityX *= bounce;
|
||||
}
|
||||
else if (pos.x > bounds.right && this.collideRight)
|
||||
{
|
||||
particle.x -= pos.x - bounds.right;
|
||||
particle.velocityX *= bounce;
|
||||
}
|
||||
|
||||
if (pos.y < bounds.y && this.collideTop)
|
||||
{
|
||||
particle.y += bounds.y - pos.y;
|
||||
particle.velocityY *= bounce;
|
||||
}
|
||||
else if (pos.y > bounds.bottom && this.collideBottom)
|
||||
{
|
||||
particle.y -= pos.y - bounds.bottom;
|
||||
particle.velocityY *= bounce;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = ParticleBounds;
|
|
@ -33,6 +33,7 @@ var StableSort = require('../../utils/array/StableSort');
|
|||
var TransformMatrix = require('../components/TransformMatrix');
|
||||
var Vector2 = require('../../math/Vector2');
|
||||
var Wrap = require('../../math/Wrap');
|
||||
var ParticleBounds = require('./ParticleBounds');
|
||||
|
||||
/**
|
||||
* Names of simple configuration properties.
|
||||
|
@ -43,10 +44,6 @@ var configFastMap = [
|
|||
'active',
|
||||
'advance',
|
||||
'blendMode',
|
||||
'collideBottom',
|
||||
'collideLeft',
|
||||
'collideRight',
|
||||
'collideTop',
|
||||
'colorEase',
|
||||
'deathCallback',
|
||||
'deathCallbackScope',
|
||||
|
@ -285,6 +282,35 @@ var configOpMap = [
|
|||
* By using the above configuration options you have an unlimited about of
|
||||
* control over how your particles behave.
|
||||
*
|
||||
* ## v3.55 Differences
|
||||
*
|
||||
* Prior to v3.60 Phaser used a `ParticleEmitterManager`. This was removed in v3.60
|
||||
* and now calling `this.add.particles` returns a `ParticleEmitter` instance instead.
|
||||
*
|
||||
* In order to streamline memory and the display list we have removed the
|
||||
* `ParticleEmitterManager` entirely. When you call `this.add.particles` you're now
|
||||
* creating a `ParticleEmitter` instance, which is being added directly to the
|
||||
* display list and can be manipulated just like any other Game Object, i.e.
|
||||
* scaled, rotated, positioned, added to a Container, etc. It now extends the
|
||||
* `GameObject` base class, meaning it's also an event emitter, which allowed us
|
||||
* to create some handy new events for particles.
|
||||
*
|
||||
* So, to create an emitter, you now give it an xy coordinate, a texture and an
|
||||
* emitter configuration object (you can also set this later, but most commonly
|
||||
* you'd do it on creation). I.e.:
|
||||
*
|
||||
* ```js
|
||||
* const emitter = this.add.particles(100, 300, 'flares', {
|
||||
* frame: 'red',
|
||||
* angle: { min: -30, max: 30 },
|
||||
* speed: 150
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* This will create a 'red flare' emitter at 100 x 300.
|
||||
*
|
||||
* Please update your code to ensure it adheres to the new function signatures.
|
||||
*
|
||||
* @class ParticleEmitter
|
||||
* @extends Phaser.GameObjects.GameObject
|
||||
* @memberof Phaser.GameObjects.Particles
|
||||
|
@ -652,60 +678,6 @@ var ParticleEmitter = new Class({
|
|||
*/
|
||||
this.viewBounds = null;
|
||||
|
||||
/**
|
||||
* A rectangular boundary constraining particle movement. Use the Emitter properties `collideLeft`,
|
||||
* `collideRight`, `collideTop` and `collideBottom` to control if a particle will rebound off
|
||||
* the sides of this boundary, or not. This happens when the particles x/y coordinate hits
|
||||
* the boundary.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitter#bounds
|
||||
* @type {?Phaser.Geom.Rectangle}
|
||||
* @default null
|
||||
* @since 3.0.0
|
||||
* @see Phaser.GameObjects.Particles.ParticleEmitter#setBounds
|
||||
*/
|
||||
this.bounds = null;
|
||||
|
||||
/**
|
||||
* Whether particles interact with the left edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitter#collideLeft
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.collideLeft = true;
|
||||
|
||||
/**
|
||||
* Whether particles interact with the right edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitter#collideRight
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.collideRight = true;
|
||||
|
||||
/**
|
||||
* Whether particles interact with the top edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitter#collideTop
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.collideTop = true;
|
||||
|
||||
/**
|
||||
* Whether particles interact with the bottom edge of the emitter {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds}.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitter#collideBottom
|
||||
* @type {boolean}
|
||||
* @default true
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.collideBottom = true;
|
||||
|
||||
/**
|
||||
* A Game Object whose position is used as the particle origin.
|
||||
*
|
||||
|
@ -964,19 +936,6 @@ var ParticleEmitter = new Class({
|
|||
this.scene.sys.updateList.remove(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets all active Particle Processors.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitter#getProcessors
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleProcessor[]} - An array of active Particle Processors.
|
||||
*/
|
||||
getProcessors: function ()
|
||||
{
|
||||
return this.processors.getAll('active', true);
|
||||
},
|
||||
|
||||
/**
|
||||
* Merges configuration settings into the emitter's current settings.
|
||||
*
|
||||
|
@ -1063,7 +1022,12 @@ var ParticleEmitter = new Class({
|
|||
|
||||
if (HasValue(config, 'bounds'))
|
||||
{
|
||||
this.setBounds(config.bounds);
|
||||
var bounds = this.addParticleBounds(config.bounds);
|
||||
|
||||
bounds.collideLeft = GetFastValue(config, 'collideLeft', true);
|
||||
bounds.collideRight = GetFastValue(config, 'collideRight', true);
|
||||
bounds.collideTop = GetFastValue(config, 'collideTop', true);
|
||||
bounds.collideBottom = GetFastValue(config, 'collideBottom', true);
|
||||
}
|
||||
|
||||
if (HasValue(config, 'followOffset'))
|
||||
|
@ -1457,23 +1421,42 @@ var ParticleEmitter = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Sets or modifies a rectangular boundary constraining the particles.
|
||||
* Creates a Particle Bounds processor and adds it to this Emitter.
|
||||
*
|
||||
* To remove the boundary, set {@link Phaser.GameObjects.Particles.ParticleEmitter#bounds} to null.
|
||||
* This processor will check to see if any of the active Particles hit
|
||||
* the defined boundary, as specified by a Rectangle shape in world-space.
|
||||
*
|
||||
* Particles will rebound off the edges of the boundary.
|
||||
* If so, they are 'rebounded' back again by having their velocity adjusted.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitter#setParticleBounds
|
||||
* The strength of the rebound is controlled by the `Particle.bounce`
|
||||
* property.
|
||||
*
|
||||
* You should be careful to ensure that you emit particles within a bounds,
|
||||
* if set, otherwise it will lead to unpredictable visual results as the
|
||||
* particles are hastily repositioned.
|
||||
*
|
||||
* The Particle Bounds processor is returned from this method. If you wish
|
||||
* to modify the area you can directly change its `bounds` property, along
|
||||
* with the `collideLeft` etc values.
|
||||
*
|
||||
* To disable the bounds you can either set its `active` property to `false`,
|
||||
* or if you no longer require it, call `ParticleEmitter.removeParticleProcessor`.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitter#addParticleBounds
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {(number|Phaser.Types.GameObjects.Particles.ParticleEmitterBounds|Phaser.Types.GameObjects.Particles.ParticleEmitterBoundsAlt)} x - The x-coordinate of the left edge of the boundary, or an object representing a rectangle.
|
||||
* @param {number} y - The y-coordinate of the top edge of the boundary.
|
||||
* @param {number} width - The width of the boundary.
|
||||
* @param {number} height - The height of the boundary.
|
||||
* @param {number} [y] - The y-coordinate of the top edge of the boundary.
|
||||
* @param {number} [width] - The width of the boundary.
|
||||
* @param {number} [height] - The height of the boundary.
|
||||
* @param {boolean} [collideLeft=true] - Whether particles interact with the left edge of the bounds.
|
||||
* @param {boolean} [collideRight=true] - Whether particles interact with the right edge of the bounds.
|
||||
* @param {boolean} [collideTop=true] - Whether particles interact with the top edge of the bounds.
|
||||
* @param {boolean} [collideBottom=true] - Whether particles interact with the bottom edge of the bounds.
|
||||
*
|
||||
* @return {this} This Particle Emitter.
|
||||
* @return {Phaser.GameObjects.Particles.ParticleBounds} The Particle Bounds processor.
|
||||
*/
|
||||
setParticleBounds: function (x, y, width, height)
|
||||
addParticleBounds: function (x, y, width, height, collideLeft, collideRight, collideTop, collideBottom)
|
||||
{
|
||||
if (typeof x === 'object')
|
||||
{
|
||||
|
@ -1485,16 +1468,7 @@ var ParticleEmitter = new Class({
|
|||
height = (HasValue(obj, 'h')) ? obj.h : obj.height;
|
||||
}
|
||||
|
||||
if (this.bounds)
|
||||
{
|
||||
this.bounds.setTo(x, y, width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bounds = new Rectangle(x, y, width, height);
|
||||
}
|
||||
|
||||
return this;
|
||||
return this.addParticleProcessor(new ParticleBounds(x, y, width, height, collideLeft, collideRight, collideTop, collideBottom));
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1922,11 +1896,11 @@ var ParticleEmitter = new Class({
|
|||
|
||||
for (var i = 0; i < zones.length; i++)
|
||||
{
|
||||
var bounds = particle.getBounds(this.worldMatrix);
|
||||
var zone = zones[i];
|
||||
|
||||
if (zones[i].willKill(bounds.centerX, bounds.centerY))
|
||||
if (zone.willKill(particle))
|
||||
{
|
||||
this.emit(Events.DEATH_ZONE, this, particle, zones[i]);
|
||||
this.emit(Events.DEATH_ZONE, this, particle, zone);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2032,6 +2006,19 @@ var ParticleEmitter = new Class({
|
|||
return processor;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets all active Particle Processors.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitter#getProcessors
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleProcessor[]} - An array of active Particle Processors.
|
||||
*/
|
||||
getProcessors: function ()
|
||||
{
|
||||
return this.processors.getAll('active', true);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Gravity Well, adds it to this Emitter and returns a reference to it.
|
||||
*
|
||||
|
@ -2718,10 +2705,7 @@ var ParticleEmitter = new Class({
|
|||
this.visible = this.follow.visible;
|
||||
}
|
||||
|
||||
if (this.deathZones.length > 0)
|
||||
{
|
||||
this.worldMatrix = this.getWorldTransformMatrix();
|
||||
}
|
||||
this.getWorldTransformMatrix(this.worldMatrix);
|
||||
|
||||
// Any particle processors?
|
||||
var processors = this.getProcessors();
|
||||
|
@ -2961,6 +2945,18 @@ var ParticleEmitter = new Class({
|
|||
return output;
|
||||
},
|
||||
|
||||
/**
|
||||
* Prints a warning to the console if you mistakenly call this function
|
||||
* thinking it works the same way as Phaser v3.55.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitter#createEmitter
|
||||
* @since 3.60.0
|
||||
*/
|
||||
createEmitter: function ()
|
||||
{
|
||||
throw new Error('createEmitter removed. See ParticleEmitter docs for info');
|
||||
},
|
||||
|
||||
/**
|
||||
* The x coordinate the particles are emitted from.
|
||||
*
|
||||
|
|
|
@ -75,8 +75,9 @@ var ParticleEmitterWebGLRenderer = function (renderer, emitter, camera, parentMa
|
|||
|
||||
camera.addToRenderList(emitter);
|
||||
|
||||
var scrollFactorX = emitter.scrollFactorX;
|
||||
var scrollFactorY = emitter.scrollFactorY;
|
||||
camMatrix.copyFrom(camera.matrix);
|
||||
|
||||
camMatrix.multiplyWithOffset(managerMatrix, -camera.scrollX * emitter.scrollFactorX, -camera.scrollY * emitter.scrollFactorY);
|
||||
|
||||
renderer.setBlendMode(emitter.blendMode);
|
||||
|
||||
|
@ -102,10 +103,6 @@ var ParticleEmitterWebGLRenderer = function (renderer, emitter, camera, parentMa
|
|||
|
||||
particleMatrix.applyITRS(particle.x, particle.y, particle.rotation, particle.scaleX, particle.scaleY);
|
||||
|
||||
camMatrix.copyFrom(camera.matrix);
|
||||
|
||||
camMatrix.multiplyWithOffset(managerMatrix, -camera.scrollX * scrollFactorX, -camera.scrollY * scrollFactorY);
|
||||
|
||||
// Undo the camera scroll
|
||||
particleMatrix.e = particle.x;
|
||||
particleMatrix.f = particle.y;
|
||||
|
|
|
@ -15,6 +15,7 @@ module.exports = {
|
|||
Events: require('./events'),
|
||||
GravityWell: require('./GravityWell'),
|
||||
Particle: require('./Particle'),
|
||||
ParticleBounds: require('./ParticleBounds'),
|
||||
ParticleEmitter: require('./ParticleEmitter'),
|
||||
ParticleProcessor: require('./ParticleProcessor'),
|
||||
Zones: require('./zones')
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
* @property {number} width - The width of the rectangle.
|
||||
* @property {number} height - The height of the rectangle.
|
||||
*
|
||||
* @see Phaser.GameObjects.Particles.ParticleEmitter#setBounds
|
||||
* @see Phaser.GameObjects.Particles.ParticleEmitter#addParticleBounds
|
||||
*/
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
* @property {number} w - The width of the rectangle.
|
||||
* @property {number} h - The height of the rectangle.
|
||||
*
|
||||
* @see Phaser.GameObjects.Particles.ParticleEmitter#setBounds
|
||||
* @see Phaser.GameObjects.Particles.ParticleEmitter#addParticleBounds
|
||||
*/
|
||||
|
|
|
@ -56,14 +56,15 @@ var DeathZone = new Class({
|
|||
* @method Phaser.GameObjects.Particles.Zones.DeathZone#willKill
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} x - The x coordinate of the Particle to be checked against this zone.
|
||||
* @param {number} y - The y coordinate of the Particle to be checked against this zone.
|
||||
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle to test against this Death Zones.
|
||||
*
|
||||
* @return {boolean} Return `true` if the Particle is to be killed, otherwise return `false`.
|
||||
*/
|
||||
willKill: function (x, y)
|
||||
willKill: function (particle)
|
||||
{
|
||||
var withinZone = this.source.contains(x, y);
|
||||
var pos = particle.worldPosition;
|
||||
|
||||
var withinZone = this.source.contains(pos.x, pos.y);
|
||||
|
||||
return (withinZone && this.killOnEnter || !withinZone && !this.killOnEnter);
|
||||
}
|
||||
|
|
|
@ -220,14 +220,22 @@ var CanvasTexture = new Class({
|
|||
* @param {number} x - The x coordinate to draw the source at.
|
||||
* @param {number} y - The y coordinate to draw the source at.
|
||||
* @param {(HTMLImageElement|HTMLCanvasElement)} source - The element to draw to this canvas.
|
||||
* @param {boolean} [update=true] - Update the internal ImageData buffer and arrays.
|
||||
*
|
||||
* @return {Phaser.Textures.CanvasTexture} This CanvasTexture.
|
||||
*/
|
||||
draw: function (x, y, source)
|
||||
draw: function (x, y, source, update)
|
||||
{
|
||||
if (update === undefined) { update = true; }
|
||||
|
||||
this.context.drawImage(source, x, y);
|
||||
|
||||
return this.update();
|
||||
if (update)
|
||||
{
|
||||
this.update();
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -241,13 +249,15 @@ var CanvasTexture = new Class({
|
|||
* @param {(string|number)} [frame] - The string-based name, or integer based index, of the Frame to get from the Texture.
|
||||
* @param {number} [x=0] - The x coordinate to draw the source at.
|
||||
* @param {number} [y=0] - The y coordinate to draw the source at.
|
||||
* @param {boolean} [update=true] - Update the internal ImageData buffer and arrays.
|
||||
*
|
||||
* @return {Phaser.Textures.CanvasTexture} This CanvasTexture.
|
||||
*/
|
||||
drawFrame: function (key, frame, x, y)
|
||||
drawFrame: function (key, frame, x, y, update)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
if (y === undefined) { y = 0; }
|
||||
if (update === undefined) { update = true; }
|
||||
|
||||
var textureFrame = this.manager.getFrame(key, frame);
|
||||
|
||||
|
@ -269,12 +279,13 @@ var CanvasTexture = new Class({
|
|||
height / res
|
||||
);
|
||||
|
||||
return this.update();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this;
|
||||
if (update)
|
||||
{
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -551,19 +562,26 @@ var CanvasTexture = new Class({
|
|||
* @param {number} [y=0] - The y coordinate of the top-left of the region to clear.
|
||||
* @param {number} [width] - The width of the region.
|
||||
* @param {number} [height] - The height of the region.
|
||||
* @param {boolean} [update=true] - Update the internal ImageData buffer and arrays.
|
||||
*
|
||||
* @return {Phaser.Textures.CanvasTexture} The Canvas Texture.
|
||||
*/
|
||||
clear: function (x, y, width, height)
|
||||
clear: function (x, y, width, height, update)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
if (y === undefined) { y = 0; }
|
||||
if (width === undefined) { width = this.width; }
|
||||
if (height === undefined) { height = this.height; }
|
||||
if (update === undefined) { update = true; }
|
||||
|
||||
this.context.clearRect(x, y, width, height);
|
||||
|
||||
return this.update();
|
||||
if (update)
|
||||
{
|
||||
this.update();
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -218,7 +218,7 @@ var Texture = new Class({
|
|||
*/
|
||||
has: function (name)
|
||||
{
|
||||
return (this.frames[name]);
|
||||
return this.frames.hasOwnProperty(name);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,13 +20,15 @@ var TilemapLayer = require('./TilemapLayer');
|
|||
var Tileset = require('./Tileset');
|
||||
|
||||
/**
|
||||
* A predicate, to test each element of the array.
|
||||
*
|
||||
* @callback TilemapFilterCallback
|
||||
*
|
||||
* @param {Phaser.GameObjects.GameObject} value - An object found in the filtered area.
|
||||
* @param {number} index - The index of the object within the array.
|
||||
* @param {Phaser.GameObjects.GameObject[]} array - An array of all the objects found.
|
||||
*
|
||||
* @return {Phaser.GameObjects.GameObject} The object.
|
||||
* @return {boolean} A value that coerces to `true` to keep the element, or to `false` otherwise.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -925,7 +927,7 @@ var Tilemap = new Class({
|
|||
|
||||
/**
|
||||
* For each object in the given object layer, run the given filter callback function. Any
|
||||
* objects that pass the filter test (i.e. where the callback returns true) will returned as a
|
||||
* objects that pass the filter test (i.e. where the callback returns true) will be returned in a
|
||||
* new array. Similar to Array.prototype.Filter in vanilla JS.
|
||||
*
|
||||
* @method Phaser.Tilemaps.Tilemap#filterObjects
|
||||
|
|
Loading…
Reference in a new issue