mirror of
https://github.com/photonstorm/phaser
synced 2024-12-23 11:33:28 +00:00
Merge pull request #3 from photonstorm/master
getting up to date with master again
This commit is contained in:
commit
208c77f3fd
14 changed files with 591 additions and 76 deletions
|
@ -4,8 +4,14 @@
|
|||
|
||||
### New Features
|
||||
|
||||
* `Line.GetEasedPoints` is a new function that will take a Line, a quantity, and an ease function, and returns an array of points where each point has been spaced out across the length of the Line based on the ease function given.
|
||||
* `XHRSettings.withCredentials` is a new boolean property that controls the `withCredentials` setting of the XHR Request made by the Loader. It indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates. You can set this on a per-file basis, or global in the Game Config.
|
||||
* `Config.loaderWithCredentials` is the new global setting for `XHRSettings.withCredentials`.
|
||||
|
||||
### Updates
|
||||
|
||||
* `XHRLoader` will now use the `XHRSettings.withCredentials` as set in the file or global loader config.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* The conditional checking if the `PathFollower` was at the end of the path or not was incorrect (thanks @samme)
|
||||
|
|
|
@ -480,6 +480,11 @@ var Config = new Class({
|
|||
*/
|
||||
this.loaderTimeout = GetValue(config, 'loader.timeout', 0);
|
||||
|
||||
/**
|
||||
* @const {boolean} Phaser.Core.Config#loaderWithCredentials - Optional XHR withCredentials value.
|
||||
*/
|
||||
this.loaderWithCredentials = GetValue(config, 'loader.withCredentials', false);
|
||||
|
||||
/*
|
||||
* Allows `plugins` property to either be an array, in which case it just replaces
|
||||
* the default plugins like previously, or a config object.
|
||||
|
|
|
@ -8,12 +8,13 @@ var Class = require('../../utils/Class');
|
|||
var Components = require('../components');
|
||||
var GameObject = require('../GameObject');
|
||||
var RopeRender = require('./RopeRender');
|
||||
var NOOP = require('../../utils/NOOP');
|
||||
var Vector2 = require('../../math/Vector2');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A Rope Game Object.
|
||||
*
|
||||
* A Ropes origin is always 0.5 x 0.5 and cannot be changed.
|
||||
*
|
||||
* @class Rope
|
||||
* @extends Phaser.GameObjects.GameObject
|
||||
|
@ -22,8 +23,10 @@ var Vector2 = require('../../math/Vector2');
|
|||
* @webglOnly
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @extends Phaser.GameObjects.Components.AlphaSingle
|
||||
* @extends Phaser.GameObjects.Components.BlendMode
|
||||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.Flip
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.Size
|
||||
|
@ -33,11 +36,12 @@ var Vector2 = require('../../math/Vector2');
|
|||
* @extends Phaser.GameObjects.Components.ScrollFactor
|
||||
*
|
||||
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
|
||||
* @param {number} x - The horizontal position of this Game Object in the world.
|
||||
* @param {number} y - The vertical position of this Game Object in the world.
|
||||
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
||||
* @param {number} [x=0] - The horizontal position of this Game Object in the world.
|
||||
* @param {number} [y=0] - The vertical position of this Game Object in the world.
|
||||
* @param {string} [texture] - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager. If not given, `__DEFAULT` is used.
|
||||
* @param {(string|integer|null)} [frame] - An optional frame from the Texture this Game Object is rendering with.
|
||||
* @param {Phaser.Types.Math.Vector2Like[]} [points] - An array containing the vertices data for this Rope. If none is provided a simple quad is created. See `setPoints` to set this post-creation.
|
||||
* @param {(integer|Phaser.Types.Math.Vector2Like[])} [points=2] - An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided a simple quad is created. See `setPoints` to set this post-creation.
|
||||
* @param {boolean} [horizontal=true] - Should the vertices of this Rope be aligned horizontally (`true`), or vertically (`false`)?
|
||||
* @param {number[]} [colors] - An optional array containing the color data for this Rope. You should provide one color value per pair of vertices.
|
||||
* @param {number[]} [alphas] - An optional array containing the alpha data for this Rope. You should provide one alpha value per pair of vertices.
|
||||
*/
|
||||
|
@ -46,8 +50,10 @@ var Rope = new Class({
|
|||
Extends: GameObject,
|
||||
|
||||
Mixins: [
|
||||
Components.AlphaSingle,
|
||||
Components.BlendMode,
|
||||
Components.Depth,
|
||||
Components.Flip,
|
||||
Components.Mask,
|
||||
Components.Pipeline,
|
||||
Components.Size,
|
||||
|
@ -60,15 +66,23 @@ var Rope = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function Rope (scene, x, y, texture, frame, points, colors, alphas)
|
||||
function Rope (scene, x, y, texture, frame, points, horizontal, colors, alphas)
|
||||
{
|
||||
if (points === undefined)
|
||||
{
|
||||
points = [ { x: 0, y: 0 } ];
|
||||
}
|
||||
if (texture === undefined) { texture = '__DEFAULT'; }
|
||||
if (points === undefined) { points = 2; }
|
||||
if (horizontal === undefined) { horizontal = true; }
|
||||
|
||||
GameObject.call(this, scene, 'Rope');
|
||||
|
||||
/**
|
||||
* The Animation Controller of this Rope.
|
||||
*
|
||||
* @name Phaser.GameObjects.Rope#anims
|
||||
* @type {Phaser.GameObjects.Components.Animation}
|
||||
* @since 3.23.0
|
||||
*/
|
||||
this.anims = new Components.Animation(this);
|
||||
|
||||
/**
|
||||
* An array containing the points data for this Rope.
|
||||
*
|
||||
|
@ -141,14 +155,17 @@ var Rope = new Class({
|
|||
this.alphas;
|
||||
|
||||
/**
|
||||
* Fill or additive mode used when blending the color values?
|
||||
* The tint fill mode.
|
||||
*
|
||||
* 0 = An additive tint (the default), where vertices colors are blended with the texture.
|
||||
* 1 = A fill tint, where the vertices colors replace the texture, but respects texture alpha.
|
||||
* 2 = A complete tint, where the vertices colors replace the texture, including alpha, entirely.
|
||||
*
|
||||
* @name Phaser.GameObjects.Rope#tintFill
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
* @type {integer}
|
||||
* @since 3.23.0
|
||||
*/
|
||||
this.tintFill = false;
|
||||
this.tintFill = (texture === '__DEFAULT') ? 2 : 0;
|
||||
|
||||
/**
|
||||
* If the Rope is marked as `dirty` it will automatically recalculate its vertices
|
||||
|
@ -160,6 +177,49 @@ var Rope = new Class({
|
|||
*/
|
||||
this.dirty = false;
|
||||
|
||||
/**
|
||||
* Are the Rope vertices aligned horizontally, in a strip, or vertically, in a column?
|
||||
*
|
||||
* This property is set during instantiation and cannot be changed directly.
|
||||
* See the `setVertical` and `setHorizontal` methods.
|
||||
*
|
||||
* @name Phaser.GameObjects.Rope#horizontal
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @since 3.23.0
|
||||
*/
|
||||
this.horizontal = horizontal;
|
||||
|
||||
/**
|
||||
* The horizontally flipped state of the Game Object.
|
||||
*
|
||||
* A Game Object that is flipped horizontally will render inversed on the horizontal axis.
|
||||
* Flipping always takes place from the middle of the texture and does not impact the scale value.
|
||||
* If this Game Object has a physics body, it will not change the body. This is a rendering toggle only.
|
||||
*
|
||||
* @name Phaser.GameObjects.Rope#_flipX
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
* @private
|
||||
* @since 3.23.0
|
||||
*/
|
||||
this._flipX = false;
|
||||
|
||||
/**
|
||||
* The vertically flipped state of the Game Object.
|
||||
*
|
||||
* A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down)
|
||||
* Flipping always takes place from the middle of the texture and does not impact the scale value.
|
||||
* If this Game Object has a physics body, it will not change the body. This is a rendering toggle only.
|
||||
*
|
||||
* @name Phaser.GameObjects.Rope#flipY
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
* @private
|
||||
* @since 3.23.0
|
||||
*/
|
||||
this._flipY = false;
|
||||
|
||||
/**
|
||||
* Internal Vector2 used for vertices updates.
|
||||
*
|
||||
|
@ -175,7 +235,10 @@ var Rope = new Class({
|
|||
this.setSizeToFrame();
|
||||
this.initPipeline('TextureTintStripPipeline');
|
||||
|
||||
this.resizeArrays(points.length);
|
||||
if (Array.isArray(points))
|
||||
{
|
||||
this.resizeArrays(points.length);
|
||||
}
|
||||
|
||||
this.setPoints(points, colors, alphas);
|
||||
|
||||
|
@ -183,14 +246,58 @@ var Rope = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* This method is left intentionally empty and does not do anything.
|
||||
* It is retained to allow a Rope to be added to a Container.
|
||||
* You should modify the alphas array values instead. See `setAlphas`.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#setAlpha
|
||||
* The Rope update loop.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#preUpdate
|
||||
* @protected
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @param {number} time - The current timestamp.
|
||||
* @param {number} delta - The delta time, in ms, elapsed since the last frame.
|
||||
*/
|
||||
preUpdate: function (time, delta)
|
||||
{
|
||||
var prevFrame = this.anims.currentFrame;
|
||||
|
||||
this.anims.update(time, delta);
|
||||
|
||||
if (this.anims.currentFrame !== prevFrame)
|
||||
{
|
||||
this.updateUVs();
|
||||
this.updateVertices();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* NOOP. Included to allow animations to play.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#updateDisplayOrigin
|
||||
* @private
|
||||
* @since 3.23.0
|
||||
*/
|
||||
setAlpha: NOOP,
|
||||
updateDisplayOrigin: function ()
|
||||
{
|
||||
// NOOP
|
||||
},
|
||||
|
||||
/**
|
||||
* Start playing the given animation.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#play
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @param {string} key - The string-based key of the animation to play.
|
||||
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
|
||||
* @param {integer} [startFrame=0] - Optionally start the animation playing from this frame index.
|
||||
*
|
||||
* @return {this} This Game Object.
|
||||
*/
|
||||
play: function (key, ignoreIfPlaying, startFrame)
|
||||
{
|
||||
this.anims.play(key, ignoreIfPlaying, startFrame);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Flags this Rope as being dirty. A dirty rope will recalculate all of its vertices data
|
||||
|
@ -210,23 +317,88 @@ var Rope = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Swap this Game Object from using a fill-tint to an additive tint.
|
||||
* Sets the alignment of the points in this Rope to be horizontal, in a strip format.
|
||||
*
|
||||
* Unlike an additive tint, a fill-tint literally replaces the pixel colors from the texture
|
||||
* with those in the tint. You can use this for effects such as making a player flash 'white'
|
||||
* if hit by something. See the `setColors` method for details of tinting the vertices.
|
||||
* Calling this method will reset this Rope. The current points, vertices, colors and alpha
|
||||
* values will be reset to thoes values given as parameters.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#setHorizontal
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @param {(integer|Phaser.Types.Math.Vector2Like[])} [points] - An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided the current points length is used.
|
||||
* @param {(number|number[])} [colors] - Either a single color value, or an array of values.
|
||||
* @param {(number|number[])} [alphas] - Either a single alpha value, or an array of values.
|
||||
*
|
||||
* @return {this} This Game Object instance.
|
||||
*/
|
||||
setHorizontal: function (points, colors, alphas)
|
||||
{
|
||||
if (points === undefined) { points = this.points.length; }
|
||||
|
||||
if (this.horizontal)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
this.horizontal = true;
|
||||
|
||||
return this.setPoints(points, colors, alphas);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the alignment of the points in this Rope to be vertical, in a column format.
|
||||
*
|
||||
* Calling this method will reset this Rope. The current points, vertices, colors and alpha
|
||||
* values will be reset to thoes values given as parameters.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#setVertical
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @param {(integer|Phaser.Types.Math.Vector2Like[])} [points] - An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided the current points length is used.
|
||||
* @param {(number|number[])} [colors] - Either a single color value, or an array of values.
|
||||
* @param {(number|number[])} [alphas] - Either a single alpha value, or an array of values.
|
||||
*
|
||||
* @return {this} This Game Object instance.
|
||||
*/
|
||||
setVertical: function (points, colors, alphas)
|
||||
{
|
||||
if (points === undefined) { points = this.points.length; }
|
||||
|
||||
if (!this.horizontal)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
this.horizontal = false;
|
||||
|
||||
return this.setPoints(points, colors, alphas);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the tint fill mode.
|
||||
*
|
||||
* Mode 0 is an additive tint, the default, which blends the vertices colors with the texture.
|
||||
* This mode respects the texture alpha.
|
||||
*
|
||||
* Mode 1 is a fill tint. Unlike an additive tint, a fill-tint literally replaces the pixel colors
|
||||
* from the texture with those in the tint. You can use this for effects such as making a player flash 'white'
|
||||
* if hit by something. This mode respects the texture alpha.
|
||||
*
|
||||
* Mode 2 is a complete tint. The texture colors and alpha are replaced entirely by the vertices colors.
|
||||
*
|
||||
* See the `setColors` method for details of how to color each of the vertices.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#setTintFill
|
||||
* @webglOnly
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @param {boolean} [value=false] - Use tint fill (`true`) or an additive tint (`false`)
|
||||
* @param {integer} [value=0] - Set to 0 for an Additive tint, 1 for a fill tint with alpha, or 2 for a fill tint without alpha.
|
||||
*
|
||||
* @return {this} This Game Object instance.
|
||||
*/
|
||||
setTintFill: function (value)
|
||||
{
|
||||
if (value === undefined) { value = false; }
|
||||
if (value === undefined) { value = 0; }
|
||||
|
||||
this.tintFill = value;
|
||||
|
||||
|
@ -339,8 +511,8 @@ var Rope = new Class({
|
|||
*
|
||||
* You can provide the values in a number of ways:
|
||||
*
|
||||
* 1) One single numeric value: `setColors(0xff0000)` - This will set a single color tint for the whole Rope.
|
||||
* 3) An array of values: `setColors([ 0xff0000, 0x00ff00, 0x0000ff ])`
|
||||
* * One single numeric value: `setColors(0xff0000)` - This will set a single color tint for the whole Rope.
|
||||
* * An array of values: `setColors([ 0xff0000, 0x00ff00, 0x0000ff ])`
|
||||
*
|
||||
* If you provide an array of values and the array has exactly the same number of values as `points` in the Rope, it
|
||||
* will use each color per rope segment.
|
||||
|
@ -438,15 +610,21 @@ var Rope = new Class({
|
|||
* ]);
|
||||
* ```
|
||||
*
|
||||
* Or, you can provide an integer to do the same thing:
|
||||
*
|
||||
* ```javascript
|
||||
* rope.setPoints(4);
|
||||
* ```
|
||||
*
|
||||
* Which will divide the Rope into 4 equally sized segments based on the frame width.
|
||||
*
|
||||
* Note that calling this method with a different number of points than the Rope has currently will
|
||||
* _reset_ the color and alpha values, unless you provide them as arguments to this method.
|
||||
*
|
||||
* See also `Rope.split`.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#setPoints
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @param {Phaser.Math.Types.Vector2Like[]} [points] - An array of points to split the Rope into.
|
||||
* @param {(integer|Phaser.Types.Math.Vector2Like[])} [points=2] - An array containing the vertices data for this Rope, or a number that indicates how many segments to split the texture frame into. If none is provided a simple quad is created.
|
||||
* @param {(number|number[])} [colors] - Either a single color value, or an array of values.
|
||||
* @param {(number|number[])} [alphas] - Either a single alpha value, or an array of values.
|
||||
*
|
||||
|
@ -454,36 +632,70 @@ var Rope = new Class({
|
|||
*/
|
||||
setPoints: function (points, colors, alphas)
|
||||
{
|
||||
if (points === undefined) { points = 2; }
|
||||
|
||||
if (typeof points === 'number')
|
||||
{
|
||||
// Generate an array based on the points
|
||||
var segments = points;
|
||||
|
||||
if (segments < 2)
|
||||
{
|
||||
segments = 2;
|
||||
}
|
||||
|
||||
points = [];
|
||||
|
||||
var s;
|
||||
var frameSegment;
|
||||
var offset;
|
||||
|
||||
if (this.horizontal)
|
||||
{
|
||||
offset = -(this.frame.halfWidth);
|
||||
frameSegment = this.frame.width / (segments - 1);
|
||||
|
||||
for (s = 0; s < segments; s++)
|
||||
{
|
||||
points.push({ x: offset + s * frameSegment, y: 0 });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = -(this.frame.halfHeight);
|
||||
frameSegment = this.frame.height / (segments - 1);
|
||||
|
||||
for (s = 0; s < segments; s++)
|
||||
{
|
||||
points.push({ x: 0, y: offset + s * frameSegment });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var total = points.length;
|
||||
var currentTotal = this.points.length;
|
||||
|
||||
if (total < 1)
|
||||
{
|
||||
console.warn('Rope: Not enough points given');
|
||||
|
||||
return this;
|
||||
}
|
||||
else if (total === 1)
|
||||
{
|
||||
points.unshift({ x: 0, y: 0 });
|
||||
total++;
|
||||
}
|
||||
|
||||
var currentUVs = this.uv;
|
||||
|
||||
if (this.points.length !== total)
|
||||
if (currentTotal !== total)
|
||||
{
|
||||
this.resizeArrays(total);
|
||||
}
|
||||
|
||||
var index = 0;
|
||||
var amount = 0;
|
||||
|
||||
for (var i = 0; i < total; i++)
|
||||
{
|
||||
index = i * 4;
|
||||
amount = i / (total - 1);
|
||||
|
||||
currentUVs[index] = amount;
|
||||
currentUVs[index + 1] = 0;
|
||||
currentUVs[index + 2] = amount;
|
||||
currentUVs[index + 3] = 1;
|
||||
}
|
||||
|
||||
this.points = points;
|
||||
|
||||
this.updateUVs();
|
||||
|
||||
if (colors !== undefined)
|
||||
{
|
||||
this.setColors(colors);
|
||||
|
@ -497,6 +709,93 @@ var Rope = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates all of the UVs based on the Rope.points and `flipX` and `flipY` settings.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#updateUVs
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @return {this} This Game Object instance.
|
||||
*/
|
||||
updateUVs: function ()
|
||||
{
|
||||
var currentUVs = this.uv;
|
||||
var total = this.points.length;
|
||||
|
||||
var u0 = this.frame.u0;
|
||||
var v0 = this.frame.v0;
|
||||
var u1 = this.frame.u1;
|
||||
var v1 = this.frame.v1;
|
||||
|
||||
var part = (u1 - u0) / (total - 1);
|
||||
|
||||
for (var i = 0; i < total; i++)
|
||||
{
|
||||
var index = i * 4;
|
||||
|
||||
var uv0;
|
||||
var uv1;
|
||||
var uv2;
|
||||
var uv3;
|
||||
|
||||
if (this.horizontal)
|
||||
{
|
||||
if (this._flipX)
|
||||
{
|
||||
uv0 = u1 - (i * part);
|
||||
uv2 = u1 - (i * part);
|
||||
}
|
||||
else
|
||||
{
|
||||
uv0 = u0 + (i * part);
|
||||
uv2 = u0 + (i * part);
|
||||
}
|
||||
|
||||
if (this._flipY)
|
||||
{
|
||||
uv1 = v1;
|
||||
uv3 = v0;
|
||||
}
|
||||
else
|
||||
{
|
||||
uv1 = v0;
|
||||
uv3 = v1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this._flipX)
|
||||
{
|
||||
uv0 = u0;
|
||||
uv2 = u1;
|
||||
}
|
||||
else
|
||||
{
|
||||
uv0 = u1;
|
||||
uv2 = u0;
|
||||
}
|
||||
|
||||
if (this._flipY)
|
||||
{
|
||||
uv1 = v1 - (i * part);
|
||||
uv3 = v1 - (i * part);
|
||||
}
|
||||
else
|
||||
{
|
||||
uv1 = v0 + (i * part);
|
||||
uv3 = v0 + (i * part);
|
||||
}
|
||||
}
|
||||
|
||||
currentUVs[index + 0] = uv0;
|
||||
currentUVs[index + 1] = uv1;
|
||||
currentUVs[index + 2] = uv2;
|
||||
currentUVs[index + 3] = uv3;
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Resizes all of the internal arrays: `vertices`, `uv`, `colors` and `alphas` to the new
|
||||
* given Rope segment total.
|
||||
|
@ -561,9 +860,11 @@ var Rope = new Class({
|
|||
return;
|
||||
}
|
||||
|
||||
var lastPoint = points[0];
|
||||
var nextPoint;
|
||||
|
||||
var lastPoint = points[0];
|
||||
|
||||
var frameSize = (this.horizontal) ? this.frame.halfHeight : this.frame.halfWidth;
|
||||
|
||||
for (var i = 0; i < total; i++)
|
||||
{
|
||||
var point = points[i];
|
||||
|
@ -577,26 +878,18 @@ var Rope = new Class({
|
|||
{
|
||||
nextPoint = point;
|
||||
}
|
||||
|
||||
|
||||
perp.x = nextPoint.y - lastPoint.y;
|
||||
perp.y = -(nextPoint.x - lastPoint.x);
|
||||
|
||||
var ratio = (1 - (i / (total - 1))) * 10;
|
||||
|
||||
if (ratio > 1)
|
||||
{
|
||||
ratio = 1;
|
||||
}
|
||||
|
||||
var perpLength = perp.length();
|
||||
var num = this.frame.halfHeight;
|
||||
|
||||
perp.x /= perpLength;
|
||||
perp.y /= perpLength;
|
||||
|
||||
perp.x *= num;
|
||||
perp.y *= num;
|
||||
|
||||
perp.x *= frameSize;
|
||||
perp.y *= frameSize;
|
||||
|
||||
vertices[index] = point.x + perp.x;
|
||||
vertices[index + 1] = point.y + perp.y;
|
||||
vertices[index + 2] = point.x - perp.x;
|
||||
|
@ -606,6 +899,82 @@ var Rope = new Class({
|
|||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the pre-destroy step for the Rope, which removes the Animation component and typed arrays.
|
||||
*
|
||||
* @method Phaser.GameObjects.Rope#preDestroy
|
||||
* @private
|
||||
* @since 3.23.0
|
||||
*/
|
||||
preDestroy: function ()
|
||||
{
|
||||
this.anims.destroy();
|
||||
|
||||
this.anims = undefined;
|
||||
|
||||
this.points = null;
|
||||
this.vertices = null;
|
||||
this.uv = null;
|
||||
this.colors = null;
|
||||
this.alphas = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* The horizontally flipped state of the Game Object.
|
||||
*
|
||||
* A Game Object that is flipped horizontally will render inversed on the horizontal axis.
|
||||
* Flipping always takes place from the middle of the texture and does not impact the scale value.
|
||||
* If this Game Object has a physics body, it will not change the body. This is a rendering toggle only.
|
||||
*
|
||||
* @name Phaser.GameObjects.Rope#flipX
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
* @since 3.23.0
|
||||
*/
|
||||
flipX: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._flipX;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._flipX = value;
|
||||
|
||||
return this.updateUVs();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The vertically flipped state of the Game Object.
|
||||
*
|
||||
* A Game Object that is flipped vertically will render inversed on the vertical axis (i.e. upside down)
|
||||
* Flipping always takes place from the middle of the texture and does not impact the scale value.
|
||||
* If this Game Object has a physics body, it will not change the body. This is a rendering toggle only.
|
||||
*
|
||||
* @name Phaser.GameObjects.Rope#flipY
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
* @since 3.23.0
|
||||
*/
|
||||
flipY: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return this._flipY;
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this._flipY = value;
|
||||
|
||||
return this.updateUVs();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -21,6 +21,7 @@ var GameObjectFactory = require('../GameObjectFactory');
|
|||
* @param {string} texture - The key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
||||
* @param {(string|integer)} [frame] - An optional frame from the Texture this Game Object is rendering with.
|
||||
* @param {Phaser.Types.Math.Vector2Like[]} [points] - An array containing the vertices data for this Rope. If none is provided a simple quad is created. See `setPoints` to set this post-creation.
|
||||
* @param {boolean} [horizontal=true] - Should the vertices of this Rope be aligned horizontally (`true`), or vertically (`false`)?
|
||||
* @param {number[]} [colors] - An optional array containing the color data for this Rope. You should provide one color value per pair of vertices.
|
||||
* @param {number[]} [alphas] - An optional array containing the alpha data for this Rope. You should provide one alpha value per pair of vertices.
|
||||
*
|
||||
|
@ -28,9 +29,13 @@ var GameObjectFactory = require('../GameObjectFactory');
|
|||
*/
|
||||
if (typeof WEBGL_RENDERER)
|
||||
{
|
||||
GameObjectFactory.register('rope', function (x, y, texture, frame, points, colors, alphas)
|
||||
GameObjectFactory.register('rope', function (x, y, texture, frame, points, horizontal, colors, alphas)
|
||||
{
|
||||
return this.displayList.add(new Rope(this.scene, x, y, texture, frame, points, colors, alphas));
|
||||
var rope = new Rope(this.scene, x, y, texture, frame, points, horizontal, colors, alphas);
|
||||
|
||||
this.displayList.add(rope);
|
||||
|
||||
return this.updateList.add(rope);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -63,11 +63,14 @@ var RopeWebGLRenderer = function (renderer, src, interpolationPercentage, camera
|
|||
var uvs = src.uv;
|
||||
var colors = src.colors;
|
||||
var alphas = src.alphas;
|
||||
var alpha = src.alpha;
|
||||
var getTint = Utils.getTintAppendFloatAlphaAndSwap;
|
||||
var roundPixels = camera.roundPixels;
|
||||
|
||||
var meshVerticesLength = vertices.length;
|
||||
var vertexCount = Math.floor(meshVerticesLength * 0.5);
|
||||
|
||||
// Because it's a triangle strip
|
||||
// Because it's a triangle strip and we don't want lots of degenerate triangles joining things up
|
||||
pipeline.flush();
|
||||
|
||||
pipeline.setTexture2D(texture, 0);
|
||||
|
@ -94,7 +97,7 @@ var RopeWebGLRenderer = function (renderer, src, interpolationPercentage, camera
|
|||
var tx = x * calcMatrix.a + y * calcMatrix.c + calcMatrix.e;
|
||||
var ty = x * calcMatrix.b + y * calcMatrix.d + calcMatrix.f;
|
||||
|
||||
if (camera.roundPixels)
|
||||
if (roundPixels)
|
||||
{
|
||||
tx = Math.round(tx);
|
||||
ty = Math.round(ty);
|
||||
|
@ -105,7 +108,7 @@ var RopeWebGLRenderer = function (renderer, src, interpolationPercentage, camera
|
|||
vertexViewF32[++vertexOffset] = uvs[i + 0];
|
||||
vertexViewF32[++vertexOffset] = uvs[i + 1];
|
||||
vertexViewF32[++vertexOffset] = tintEffect;
|
||||
vertexViewU32[++vertexOffset] = Utils.getTintAppendFloatAlphaAndSwap(colors[colorIndex], camera.alpha * alphas[colorIndex]);
|
||||
vertexViewU32[++vertexOffset] = getTint(colors[colorIndex], camera.alpha * (alphas[colorIndex] * alpha));
|
||||
|
||||
colorIndex++;
|
||||
}
|
||||
|
|
114
src/geom/line/GetEasedPoints.js
Normal file
114
src/geom/line/GetEasedPoints.js
Normal file
|
@ -0,0 +1,114 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2020 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var DistanceBetweenPoints = require('../../math/distance/DistanceBetweenPoints');
|
||||
var GetEaseFunction = require('../../tweens/builders/GetEaseFunction');
|
||||
var Point = require('../point/Point');
|
||||
|
||||
/**
|
||||
* Returns an array of `quantity` Points where each point is taken from the given Line,
|
||||
* spaced out according to the ease function specified.
|
||||
*
|
||||
* ```javascript
|
||||
* const line = new Phaser.Geom.Line(100, 300, 700, 300);
|
||||
* const points = Phaser.Geom.Line.GetEasedPoints(line, 'sine.out', 32)
|
||||
* ```
|
||||
*
|
||||
* In the above example, the `points` array will contain 32 points spread-out across
|
||||
* the length of `line`, where the position of each point is determined by the `Sine.out`
|
||||
* ease function.
|
||||
*
|
||||
* You can optionally provide a collinear threshold. In this case, the resulting points
|
||||
* are checked against each other, and if they are `< collinearThreshold` distance apart,
|
||||
* they are dropped from the results. This can help avoid lots of clustered points at
|
||||
* far ends of the line with tightly-packed eases such as Quartic. Leave the value set
|
||||
* to zero to skip this check.
|
||||
*
|
||||
* Note that if you provide a collinear threshold, the resulting array may not always
|
||||
* contain `quantity` points.
|
||||
*
|
||||
* @function Phaser.Geom.Line.GetEasedPoints
|
||||
* @since 3.23.0
|
||||
*
|
||||
* @generic {Phaser.Geom.Point[]} O - [out,$return]
|
||||
*
|
||||
* @param {Phaser.Geom.Line} line - The Line object.
|
||||
* @param {(string|function)} ease - The ease to use. This can be either a string from the EaseMap, or a custom function.
|
||||
* @param {integer} quantity - The number of points to return. Note that if you provide a `collinearThreshold`, the resulting array may not always contain this number of points.
|
||||
* @param {number} [collinearThreshold=0] - An optional threshold. The final array is reduced so that each point is spaced out at least this distance apart. This helps reduce clustering in noisey eases.
|
||||
* @param {number[]} [easeParams] - An optional array of ease parameters to go with the ease.
|
||||
*
|
||||
* @return {Phaser.Geom.Point[]} An array of Geom.Points containing the coordinates of the points on the line.
|
||||
*/
|
||||
var GetEasedPoints = function (line, ease, quantity, collinearThreshold, easeParams)
|
||||
{
|
||||
if (collinearThreshold === undefined) { collinearThreshold = 0; }
|
||||
if (easeParams === undefined) { easeParams = []; }
|
||||
|
||||
var results = [];
|
||||
|
||||
var x1 = line.x1;
|
||||
var y1 = line.y1;
|
||||
|
||||
var spaceX = line.x2 - x1;
|
||||
var spaceY = line.y2 - y1;
|
||||
|
||||
var easeFunc = GetEaseFunction(ease, easeParams);
|
||||
|
||||
var i;
|
||||
var v;
|
||||
var q = quantity - 1;
|
||||
|
||||
for (i = 0; i < q; i++)
|
||||
{
|
||||
v = easeFunc(i / q);
|
||||
|
||||
results.push(new Point(x1 + (spaceX * v), y1 + (spaceY * v)));
|
||||
}
|
||||
|
||||
// Always include the end of the line
|
||||
v = easeFunc(1);
|
||||
|
||||
results.push(new Point(x1 + (spaceX * v), y1 + (spaceY * v)));
|
||||
|
||||
// Remove collinear parts
|
||||
if (collinearThreshold > 0)
|
||||
{
|
||||
var prevPoint = results[0];
|
||||
|
||||
// Store the new results here
|
||||
var sortedResults = [ prevPoint ];
|
||||
|
||||
for (i = 1; i < results.length - 1; i++)
|
||||
{
|
||||
var point = results[i];
|
||||
|
||||
if (DistanceBetweenPoints(prevPoint, point) >= collinearThreshold)
|
||||
{
|
||||
sortedResults.push(point);
|
||||
prevPoint = point;
|
||||
}
|
||||
}
|
||||
|
||||
// Top and tail
|
||||
var endPoint = results[results.length - 1];
|
||||
|
||||
if (DistanceBetweenPoints(prevPoint, endPoint) < collinearThreshold)
|
||||
{
|
||||
sortedResults.pop();
|
||||
}
|
||||
|
||||
sortedResults.push(endPoint);
|
||||
|
||||
return sortedResults;
|
||||
}
|
||||
else
|
||||
{
|
||||
return results;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = GetEasedPoints;
|
|
@ -13,6 +13,7 @@ Line.Clone = require('./Clone');
|
|||
Line.CopyFrom = require('./CopyFrom');
|
||||
Line.Equals = require('./Equals');
|
||||
Line.Extend = require('./Extend');
|
||||
Line.GetEasedPoints = require('./GetEasedPoints');
|
||||
Line.GetMidPoint = require('./GetMidPoint');
|
||||
Line.GetNearestPoint = require('./GetNearestPoint');
|
||||
Line.GetNormal = require('./GetNormal');
|
||||
|
|
|
@ -194,7 +194,8 @@ var LoaderPlugin = new Class({
|
|||
GetFastValue(sceneConfig, 'async', gameConfig.loaderAsync),
|
||||
GetFastValue(sceneConfig, 'user', gameConfig.loaderUser),
|
||||
GetFastValue(sceneConfig, 'password', gameConfig.loaderPassword),
|
||||
GetFastValue(sceneConfig, 'timeout', gameConfig.loaderTimeout)
|
||||
GetFastValue(sceneConfig, 'timeout', gameConfig.loaderTimeout),
|
||||
GetFastValue(sceneConfig, 'withCredentials', gameConfig.loaderWithCredentials)
|
||||
);
|
||||
|
||||
/**
|
||||
|
|
|
@ -45,6 +45,11 @@ var XHRLoader = function (file, globalXHRSettings)
|
|||
xhr.overrideMimeType(config.overrideMimeType);
|
||||
}
|
||||
|
||||
if (config.withCredentials)
|
||||
{
|
||||
xhr.withCredentials = true;
|
||||
}
|
||||
|
||||
// After a successful request, the xhr.response property will contain the requested data as a DOMString, ArrayBuffer, Blob, or Document (depending on what was set for responseType.)
|
||||
|
||||
xhr.onload = file.onLoad.bind(file, xhr);
|
||||
|
|
|
@ -15,16 +15,18 @@
|
|||
* @param {string} [user=''] - Optional username for the XHR request.
|
||||
* @param {string} [password=''] - Optional password for the XHR request.
|
||||
* @param {integer} [timeout=0] - Optional XHR timeout value.
|
||||
* @param {boolean} [withCredentials=false] - Optional XHR withCredentials value.
|
||||
*
|
||||
* @return {Phaser.Types.Loader.XHRSettingsObject} The XHRSettings object as used by the Loader.
|
||||
*/
|
||||
var XHRSettings = function (responseType, async, user, password, timeout)
|
||||
var XHRSettings = function (responseType, async, user, password, timeout, withCredentials)
|
||||
{
|
||||
if (responseType === undefined) { responseType = ''; }
|
||||
if (async === undefined) { async = true; }
|
||||
if (user === undefined) { user = ''; }
|
||||
if (password === undefined) { password = ''; }
|
||||
if (timeout === undefined) { timeout = 0; }
|
||||
if (withCredentials === undefined) { withCredentials = false; }
|
||||
|
||||
// Before sending a request, set the xhr.responseType to "text",
|
||||
// "arraybuffer", "blob", or "document", depending on your data needs.
|
||||
|
@ -50,7 +52,10 @@ var XHRSettings = function (responseType, async, user, password, timeout)
|
|||
requestedWith: false,
|
||||
|
||||
// overrideMimeType
|
||||
overrideMimeType: undefined
|
||||
overrideMimeType: undefined,
|
||||
|
||||
// withCredentials
|
||||
withCredentials: withCredentials
|
||||
|
||||
};
|
||||
};
|
||||
|
|
|
@ -11,4 +11,5 @@
|
|||
* @property {(string|undefined)} [headerValue] - This value is used to populate the XHR `setRequestHeader` and is undefined by default.
|
||||
* @property {(string|undefined)} [requestedWith] - This value is used to populate the XHR `setRequestHeader` and is undefined by default.
|
||||
* @property {(string|undefined)} [overrideMimeType] - Provide a custom mime-type to use instead of the default.
|
||||
* @property {boolean} [withCredentials=false] - The withCredentials property indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates. Setting withCredentials has no effect on same-site requests.
|
||||
*/
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
* @function Phaser.Math.Angle.BetweenPoints
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(Phaser.Geom.Point|object)} point1 - The first point.
|
||||
* @param {(Phaser.Geom.Point|object)} point2 - The second point.
|
||||
* @param {Phaser.Types.Math.Vector2Like} point1 - The first point.
|
||||
* @param {Phaser.Types.Math.Vector2Like} point2 - The second point.
|
||||
*
|
||||
* @return {number} The angle in radians.
|
||||
*/
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* @function Phaser.Math.Angle.BetweenPointsY
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(Phaser.Geom.Point|object)} point1 - The first point.
|
||||
* @param {(Phaser.Geom.Point|object)} point2 - The second point.
|
||||
* @param {Phaser.Types.Math.Vector2Like} point1 - The first point.
|
||||
* @param {Phaser.Types.Math.Vector2Like} point2 - The second point.
|
||||
*
|
||||
* @return {number} The angle in radians.
|
||||
*/
|
||||
|
|
|
@ -44,7 +44,7 @@ var GetEaseFunction = function (ease, easeParams)
|
|||
{
|
||||
// quad.in = Quad.easeIn
|
||||
// quad.out = Quad.easeOut
|
||||
// quad.inout =Quad.easeInOut
|
||||
// quad.inout = Quad.easeInOut
|
||||
|
||||
direction = ease.substr(ease.indexOf('.') + 1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue