mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Merge branch 'spatial-sound' of https://github.com/alxwest/phaser into spatial-sound
This commit is contained in:
commit
2df3d5979d
26 changed files with 34324 additions and 34042 deletions
|
@ -1,8 +1,24 @@
|
|||
## Version 3.60.0 - Miku - in development
|
||||
|
||||
### New Features - Plane Game Object
|
||||
|
||||
Phaser v3.60 contains a new native Plane Game Object. The Plane Game Object is a helper class that takes the Mesh Game Object and extends it, allowing for fast and easy creation of Planes. A Plane is a one-sided grid of cells, where you specify the number of cells in each dimension. The Plane can have a texture that is either repeated (tiled) across each cell, or applied to the full Plane.
|
||||
|
||||
The Plane can then be manipulated in 3D space, with rotation across all 3 axis.
|
||||
|
||||
This allows you to create effects not possible with regular Sprites, such as perspective distortion. You can also adjust the vertices on a per-vertex basis. Plane data becomes part of the WebGL batch, just like standard Sprites, so doesn't introduce any additional shader overhead. Because the Plane just generates vertices into the WebGL batch, like any other Sprite, you can use all of the common Game Object components on a Plane too, such as a custom pipeline, mask, blend mode or texture.
|
||||
|
||||
You can use the `uvScroll` and `uvScale` methods to adjust the placement and scaling of the texture if this Plane is using a single texture, and not a frame from a texture atlas or sprite sheet.
|
||||
|
||||
The Plane Game Object also has the Animation component, allowing you to play animations across the Plane just as you would with a Sprite.
|
||||
|
||||
While a Plane cannot be enabled for input it does have the methods `hasFaceAt` and `getFaceAt` which can be used with Pointer coordinates to detect if they have clicked on Plane face, or not.
|
||||
|
||||
As of Phaser 3.60 this Game Object is WebGL only. Please see the new examples and documentation for how to use it.
|
||||
|
||||
### New Features - Nine Slice Game Object
|
||||
|
||||
Phaser 3.60 contains a new native Nine Slice Game Object. A Nine Slice Game Object allows you to display a texture-based object that can be stretched both horizontally and vertically, but that retains fixed-sized corners. The dimensions of the corners are set via the parameters to the class. When you resize a Nine Slice Game Object only the middle sections of the texture stretch. This is extremely useful for UI and button-like elements, where you need them to expand to accommodate the content without distorting the texture.
|
||||
Phaser v3.60 contains a new native Nine Slice Game Object. A Nine Slice Game Object allows you to display a texture-based object that can be stretched both horizontally and vertically, but that retains fixed-sized corners. The dimensions of the corners are set via the parameters to the class. When you resize a Nine Slice Game Object only the middle sections of the texture stretch. This is extremely useful for UI and button-like elements, where you need them to expand to accommodate the content without distorting the texture.
|
||||
|
||||
The texture you provide for this Game Object should be based on the following layout structure:
|
||||
|
||||
|
@ -52,9 +68,7 @@ you must supply all parameters.
|
|||
The _minimum_ width this Game Object can be is the total of `leftWidth` + `rightWidth`. The _minimum_ height this Game Object
|
||||
can be is the total of `topHeight` + `bottomHeight`. If you need to display this object at a smaller size, you can scale it.
|
||||
|
||||
In terms of performance, using a 3 slice Game Object is the equivalent of having 3 Sprites in a row. Using a 9 slice Game Object is the equivalent
|
||||
of having 9 Sprites in a row. The vertices of this object are all batched together and can co-exist with other Sprites and graphics on the display
|
||||
list, without incurring any additional overhead.
|
||||
In terms of performance, using a 3 slice Game Object is the equivalent of having 3 Sprites in a row. Using a 9 slice Game Object is the equivalent of having 9 Sprites in a row. The vertices of this object are all batched together and can co-exist with other Sprites and graphics on the display list, without incurring any additional overhead.
|
||||
|
||||
As of Phaser 3.60 this Game Object is WebGL only. Please see the new examples and documentation for how to use it.
|
||||
|
||||
|
@ -801,6 +815,7 @@ There are breaking changes from previous versions of Phaser.
|
|||
* All of the following Texture Manager methods will now allow you to pass in a Phaser Texture as the `source` parameter: `addSpriteSheet`, `addAtlas`, `addAtlasJSONArray`, `addAtlasJSONHash`, `addAtlasXML` and `addAtlasUnity`. This allows you to add sprite sheet or atlas data to existing textures, or textures that came from external sources, such as SVG files, canvas elements or Dynamic Textures.
|
||||
* `Game.pause` is a new method that will pause the entire game and all Phaser systems.
|
||||
* `Game.resume` is a new method that will resume the entire game and resume all of Phaser's systems.
|
||||
* `Game.isPaused` is a new boolean that tracks if the Game loop is paused, or not (and can also be toggled directly)
|
||||
* `ScaleManager.getViewPort` is a new method that will return a Rectangle geometry object that matches the visible area of the screen, or the given Camera instance (thanks @rexrainbow)
|
||||
* When starting a Scene and using an invalid key, Phaser will now raise a console warning informing you of this, instead of silently failing. Fix #5811 (thanks @ubershmekel)
|
||||
* `GameObjects.Layer.addToDisplayList` and `removeFromDisplayList` are new methods that allows for you to now add a Layer as a child of another Layer. Fix #5799 (thanks @samme)
|
||||
|
@ -857,6 +872,7 @@ The following are API-breaking, in that a new optional parameter has been insert
|
|||
|
||||
### Updates
|
||||
|
||||
* `Time.Clock.startTime` is a new property that stores the time the Clock (and therefore the Scene) was started. This can be useful for comparing against the current time to see how much real world time has elapsed (thanks @samme)
|
||||
* `ColorMatrix._matrix` and `_data` are now Float32Arrays.
|
||||
* Calling the `ColorMatrix.set`, `reset` and `getData` methods all now use the built-in Float32 Array operations, making them considerably faster.
|
||||
* `ColorMatrix.BLACK_WHITE` is a new constant used by blackwhite operations.
|
||||
|
@ -976,6 +992,7 @@ ArtemSiz)
|
|||
|
||||
### Bug Fixes
|
||||
|
||||
* The `SpriteSheetFromAtlas` parser was using the incorrect `sourceIndex` to grab frames from a given texture. This caused a crash whenever a trimmed spritesheet was added from any multiatlas image other than the first (thanks @Bambosh)
|
||||
* The `maxSpeed` setting in Arcade Physics wasn't recalculated during the Body update, prior to being compared, leading to inconsistent results. Fix #6329 (thanks @Bambosh)
|
||||
* Several paths have been fixed in the `phaser-core.js` entry point (thanks @pavle-goloskokovic)
|
||||
* When a Game Object had Input Debug Enabled the debug image would be incorrectly offset if the Game Object was attached to was scaled and the hit area shape was smaller, or offset, from the Game Object. Fix #4905 #6317 (thanks @PavelMishin @justinlueders)
|
||||
|
|
65464
plugins/spine/dist/SpinePlugin.js
vendored
65464
plugins/spine/dist/SpinePlugin.js
vendored
File diff suppressed because it is too large
Load diff
1273
plugins/spine/dist/SpinePlugin.min.js
vendored
1273
plugins/spine/dist/SpinePlugin.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -341,6 +341,17 @@ var Game = new Class({
|
|||
*/
|
||||
this.hasFocus = false;
|
||||
|
||||
/**
|
||||
* Is the Game currently paused? This will stop everything from updating,
|
||||
* except the `TimeStep` and related RequestAnimationFrame or setTimeout.
|
||||
* Those will continue stepping, but the core Game step will be skipped.
|
||||
*
|
||||
* @name Phaser.Game#isPaused
|
||||
* @type {boolean}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.isPaused = false;
|
||||
|
||||
// Wait for the DOM Ready event, then call boot.
|
||||
DOMContentLoaded(this.boot.bind(this));
|
||||
},
|
||||
|
@ -467,6 +478,11 @@ var Game = new Class({
|
|||
return this.runDestroy();
|
||||
}
|
||||
|
||||
if (this.isPaused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var eventEmitter = this.events;
|
||||
|
||||
// Global Managers like Input and Sound update in the prestep
|
||||
|
@ -531,6 +547,11 @@ var Game = new Class({
|
|||
return this.runDestroy();
|
||||
}
|
||||
|
||||
if (this.isPaused)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var eventEmitter = this.events;
|
||||
|
||||
// Global Managers like Input and Sound update in the prestep
|
||||
|
@ -586,7 +607,14 @@ var Game = new Class({
|
|||
*/
|
||||
pause: function ()
|
||||
{
|
||||
this.onHidden();
|
||||
var wasPaused = this.isPaused;
|
||||
|
||||
this.isPaused = true;
|
||||
|
||||
if (!wasPaused)
|
||||
{
|
||||
this.events.emit(Events.PAUSE);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -616,7 +644,14 @@ var Game = new Class({
|
|||
*/
|
||||
resume: function ()
|
||||
{
|
||||
this.onVisible();
|
||||
var wasPaused = this.isPaused;
|
||||
|
||||
this.isPaused = false;
|
||||
|
||||
if (wasPaused)
|
||||
{
|
||||
this.events.emit(Events.RESUME);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
*
|
||||
* @property {string} [default] - The default physics system. It will be started for each scene. Phaser provides 'arcade', 'impact', and 'matter'.
|
||||
* @property {Phaser.Types.Physics.Arcade.ArcadeWorldConfig} [arcade] - Arcade Physics configuration.
|
||||
* @property {Phaser.Types.Physics.Matter.MatterWorldConfig} [matter] - Matter Physics configuration.
|
||||
* @property {Phaser.Types.Physics.Matter.MatterWorldConfig} [matter] - Matter Physics configuration.
|
||||
*/
|
||||
|
|
|
@ -130,16 +130,19 @@ if (typeof WEBGL_RENDERER)
|
|||
GameObjects.Mesh = require('./mesh/Mesh');
|
||||
GameObjects.NineSlice = require('./nineslice/NineSlice');
|
||||
GameObjects.PointLight = require('./pointlight/PointLight');
|
||||
GameObjects.Plane = require('./plane/Plane');
|
||||
|
||||
GameObjects.Factories.Shader = require('./shader/ShaderFactory');
|
||||
GameObjects.Factories.Mesh = require('./mesh/MeshFactory');
|
||||
GameObjects.Factories.NineSlice = require('./nineslice/NineSliceFactory');
|
||||
GameObjects.Factories.PointLight = require('./pointlight/PointLightFactory');
|
||||
GameObjects.Factories.Plane = require('./plane/PlaneFactory');
|
||||
|
||||
GameObjects.Creators.Shader = require('./shader/ShaderCreator');
|
||||
GameObjects.Creators.Mesh = require('./mesh/MeshCreator');
|
||||
GameObjects.Creators.NineSlice = require('./nineslice/NineSliceCreator');
|
||||
GameObjects.Creators.PointLight = require('./pointlight/PointLightCreator');
|
||||
GameObjects.Creators.Plane = require('./plane/PlaneCreator');
|
||||
|
||||
GameObjects.Light = require('./lights/Light');
|
||||
GameObjects.LightsManager = require('./lights/LightsManager');
|
||||
|
|
|
@ -9,11 +9,12 @@ var Components = require('../components');
|
|||
var DegToRad = require('../../math/DegToRad');
|
||||
var Face = require('../../geom/mesh/Face');
|
||||
var GameObject = require('../GameObject');
|
||||
var GenerateVerts = require('../../geom/mesh/GenerateVerts');
|
||||
var GenerateObjVerts = require('../../geom/mesh/GenerateObjVerts');
|
||||
var GenerateVerts = require('../../geom/mesh/GenerateVerts');
|
||||
var GetCalcMatrix = require('../GetCalcMatrix');
|
||||
var Matrix4 = require('../../math/Matrix4');
|
||||
var MeshRender = require('./MeshRender');
|
||||
var RadToDeg = require('../../math/RadToDeg');
|
||||
var StableSort = require('../../utils/array/StableSort');
|
||||
var Vector3 = require('../../math/Vector3');
|
||||
var Vertex = require('../../geom/mesh/Vertex');
|
||||
|
@ -62,13 +63,14 @@ var Vertex = require('../../geom/mesh/Vertex');
|
|||
* @extends Phaser.GameObjects.Components.AlphaSingle
|
||||
* @extends Phaser.GameObjects.Components.BlendMode
|
||||
* @extends Phaser.GameObjects.Components.Depth
|
||||
* @extends Phaser.GameObjects.Components.FX
|
||||
* @extends Phaser.GameObjects.Components.Mask
|
||||
* @extends Phaser.GameObjects.Components.Pipeline
|
||||
* @extends Phaser.GameObjects.Components.ScrollFactor
|
||||
* @extends Phaser.GameObjects.Components.Size
|
||||
* @extends Phaser.GameObjects.Components.Texture
|
||||
* @extends Phaser.GameObjects.Components.Transform
|
||||
* @extends Phaser.GameObjects.Components.Visible
|
||||
* @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.
|
||||
|
@ -91,13 +93,14 @@ var Mesh = new Class({
|
|||
Components.AlphaSingle,
|
||||
Components.BlendMode,
|
||||
Components.Depth,
|
||||
Components.FX,
|
||||
Components.Mask,
|
||||
Components.Pipeline,
|
||||
Components.ScrollFactor,
|
||||
Components.Size,
|
||||
Components.Texture,
|
||||
Components.Transform,
|
||||
Components.Visible,
|
||||
Components.ScrollFactor,
|
||||
MeshRender
|
||||
],
|
||||
|
||||
|
@ -345,6 +348,22 @@ var Mesh = new Class({
|
|||
*/
|
||||
this.ignoreDirtyCache = false;
|
||||
|
||||
/**
|
||||
* The Camera fov (field of view) in degrees.
|
||||
*
|
||||
* This is set automatically as part of the `Mesh.setPerspective` call, but exposed
|
||||
* here for additional math.
|
||||
*
|
||||
* Do not modify this property directly, doing so will not change the fov. For that,
|
||||
* call the respective Mesh methods.
|
||||
*
|
||||
* @name Phaser.GameObjects.Mesh#fov
|
||||
* @type {number}
|
||||
* @readonly
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.fov;
|
||||
|
||||
var renderer = scene.sys.renderer;
|
||||
|
||||
this.setPosition(x, y);
|
||||
|
@ -409,8 +428,11 @@ var Mesh = new Class({
|
|||
/**
|
||||
* Translates the view position of this Mesh on the z axis by the given amount.
|
||||
*
|
||||
* As the default `panZ` value is 0, vertices with `z=0` (the default) need special care or else they will not display as they are behind the camera.
|
||||
* Consider using `mesh.panZ(mesh.height / (2 * Math.tan(Math.PI / 16)))`, which will interpret vertex geometry 1:1 with pixel geometry (or see `setOrtho`).
|
||||
* As the default `panZ` value is 0, vertices with `z=0` (the default) need special
|
||||
* care or else they will not display as they are "behind" the camera.
|
||||
*
|
||||
* Consider using `mesh.panZ(mesh.height / (2 * Math.tan(Math.PI / 16)))`,
|
||||
* which will interpret vertex geometry 1:1 with pixel geometry (or see `setOrtho`).
|
||||
*
|
||||
* @method Phaser.GameObjects.Mesh#panZ
|
||||
* @since 3.50.0
|
||||
|
@ -429,7 +451,7 @@ var Mesh = new Class({
|
|||
/**
|
||||
* Builds a new perspective projection matrix from the given values.
|
||||
*
|
||||
* These are also the initial projection matrix & parameters for `Mesh` (and see `panZ` for more discussion).
|
||||
* These are also the initial projection matrix and parameters for `Mesh` (see `Mesh.panZ` for more discussion).
|
||||
*
|
||||
* See also `setOrtho`.
|
||||
*
|
||||
|
@ -448,6 +470,8 @@ var Mesh = new Class({
|
|||
if (near === undefined) { near = 0.01; }
|
||||
if (far === undefined) { far = 1000; }
|
||||
|
||||
this.fov = fov;
|
||||
|
||||
this.projectionMatrix.perspective(DegToRad(fov), width / height, near, far);
|
||||
|
||||
this.dirtyCache[10] = 1;
|
||||
|
@ -482,6 +506,8 @@ var Mesh = new Class({
|
|||
if (near === undefined) { near = -1000; }
|
||||
if (far === undefined) { far = 1000; }
|
||||
|
||||
this.fov = 0;
|
||||
|
||||
this.projectionMatrix.ortho(-scaleX, scaleX, -scaleY, scaleY, near, far);
|
||||
|
||||
this.dirtyCache[10] = 1;
|
||||
|
@ -773,6 +799,42 @@ var Mesh = new Class({
|
|||
return this.faces[index];
|
||||
},
|
||||
|
||||
/**
|
||||
* Tests to see if _any_ face in this Mesh intersects with the given coordinates.
|
||||
*
|
||||
* The given position is translated through the matrix of this Mesh and the given Camera,
|
||||
* before being compared against the vertices.
|
||||
*
|
||||
* @method Phaser.GameObjects.Mesh#hasFaceAt
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} x - The x position to check against.
|
||||
* @param {number} y - The y position to check against.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} [camera] - The camera to pass the coordinates through. If not give, the default Scene Camera is used.
|
||||
*
|
||||
* @return {boolean} Returns `true` if _any_ face of this Mesh intersects with the given coordinate, otherwise `false`.
|
||||
*/
|
||||
hasFaceAt: function (x, y, camera)
|
||||
{
|
||||
if (camera === undefined) { camera = this.scene.sys.cameras.main; }
|
||||
|
||||
var calcMatrix = GetCalcMatrix(this, camera).calc;
|
||||
|
||||
var faces = this.faces;
|
||||
|
||||
for (var i = 0; i < faces.length; i++)
|
||||
{
|
||||
var face = faces[i];
|
||||
|
||||
if (face.contains(x, y, calcMatrix))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Return an array of Face objects from this Mesh that intersect with the given coordinates.
|
||||
*
|
||||
|
@ -1116,6 +1178,82 @@ var Mesh = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Scrolls the UV texture coordinates of all faces in this Mesh by
|
||||
* adding the given x/y amounts to them.
|
||||
*
|
||||
* If you only wish to scroll one coordinate, pass a value of zero
|
||||
* to the other.
|
||||
*
|
||||
* Use small values for scrolling. UVs are set from the range 0
|
||||
* to 1, so you should increment (or decrement) them by suitably
|
||||
* small values, such as 0.01.
|
||||
*
|
||||
* Due to a limitation in WebGL1 you can only UV scroll textures
|
||||
* that are a power-of-two in size. Scrolling NPOT textures will
|
||||
* work but will result in clamping the pixels to the edges.
|
||||
*
|
||||
* Note that if this Mesh is using a _frame_ from a texture atlas
|
||||
* then you will be unable to UV scroll its texture.
|
||||
*
|
||||
* @method Phaser.GameObjects.Mesh#uvScroll
|
||||
* @webglOnly
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} x - The amount to horizontally shift the UV coordinates by.
|
||||
* @param {number} y - The amount to vertically shift the UV coordinates by.
|
||||
*
|
||||
* @return {this} This Game Object instance.
|
||||
*/
|
||||
uvScroll: function (x, y)
|
||||
{
|
||||
var faces = this.faces;
|
||||
|
||||
for (var i = 0; i < faces.length; i++)
|
||||
{
|
||||
faces[i].scrollUV(x, y);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Scales the UV texture coordinates of all faces in this Mesh by
|
||||
* the exact given amounts.
|
||||
*
|
||||
* If you only wish to scale one coordinate, pass a value of one
|
||||
* to the other.
|
||||
*
|
||||
* Due to a limitation in WebGL1 you can only UV scale textures
|
||||
* that are a power-of-two in size. Scaling NPOT textures will
|
||||
* work but will result in clamping the pixels to the edges if
|
||||
* you scale beyond a value of 1. Scaling below 1 will work
|
||||
* regardless of texture size.
|
||||
*
|
||||
* Note that if this Mesh is using a _frame_ from a texture atlas
|
||||
* then you will be unable to UV scale its texture.
|
||||
*
|
||||
* @method Phaser.GameObjects.Mesh#uvScale
|
||||
* @webglOnly
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} x - The amount to horizontally scale the UV coordinates by.
|
||||
* @param {number} y - The amount to vertically scale the UV coordinates by.
|
||||
*
|
||||
* @return {this} This Game Object instance.
|
||||
*/
|
||||
uvScale: function (x, y)
|
||||
{
|
||||
var faces = this.faces;
|
||||
|
||||
for (var i = 0; i < faces.length; i++)
|
||||
{
|
||||
faces[i].scaleUV(x, y);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* The tint value being applied to the whole of the Game Object.
|
||||
* This property is a setter-only.
|
||||
|
@ -1131,7 +1269,77 @@ var Mesh = new Class({
|
|||
{
|
||||
this.setTint(value);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The x rotation of the Model in 3D space, as specified in degrees.
|
||||
*
|
||||
* If you need the value in radians use the `modelRotation.x` property directly.
|
||||
*
|
||||
* @method Phaser.GameObjects.Mesh#rotateX
|
||||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
rotateX: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return RadToDeg(this.modelRotation.x);
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.modelRotation.x = DegToRad(value);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The y rotation of the Model in 3D space, as specified in degrees.
|
||||
*
|
||||
* If you need the value in radians use the `modelRotation.y` property directly.
|
||||
*
|
||||
* @method Phaser.GameObjects.Mesh#rotateY
|
||||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
rotateY: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return RadToDeg(this.modelRotation.y);
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.modelRotation.y = DegToRad(value);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* The z rotation of the Model in 3D space, as specified in degrees.
|
||||
*
|
||||
* If you need the value in radians use the `modelRotation.z` property directly.
|
||||
*
|
||||
* @method Phaser.GameObjects.Mesh#rotateZ
|
||||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
rotateZ: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
return RadToDeg(this.modelRotation.z);
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
this.modelRotation.z = DegToRad(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Mesh;
|
||||
|
|
|
@ -937,7 +937,8 @@ var ParticleEmitter = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Merges configuration settings into the emitter's current settings.
|
||||
* Takes an Emitter Configuration file and resets this Emitter, using any
|
||||
* properties defined in the config to then set it up again.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitter#setConfig
|
||||
* @since 3.60.0
|
||||
|
@ -1958,9 +1959,10 @@ var ParticleEmitter = new Class({
|
|||
* @method Phaser.GameObjects.Particles.ParticleEmitter#addParticleProcessor
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.Particles.ParticleProcessor} processor - The Particle Processor to add to this Emitter Manager.
|
||||
* @generic {Phaser.GameObjects.Particles.ParticleProcessor} T
|
||||
* @param {T} processor - The Particle Processor to add to this Emitter Manager.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleProcessor} The Particle Processor that was added to this Emitter Manager.
|
||||
* @return {T} The Particle Processor that was added to this Emitter Manager.
|
||||
*/
|
||||
addParticleProcessor: function (processor)
|
||||
{
|
||||
|
@ -1990,9 +1992,10 @@ var ParticleEmitter = new Class({
|
|||
* @method Phaser.GameObjects.Particles.ParticleEmitter#removeParticleProcessor
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.Particles.ParticleProcessor} processor - The Particle Processor to remove from this Emitter Manager.
|
||||
* @generic {Phaser.GameObjects.Particles.ParticleProcessor} T
|
||||
* @param {T} processor - The Particle Processor to remove from this Emitter Manager.
|
||||
*
|
||||
* @return {?Phaser.GameObjects.Particles.ParticleProcessor} The Particle Processor that was removed, or null if it could not be found.
|
||||
* @return {?T} The Particle Processor that was removed, or null if it could not be found.
|
||||
*/
|
||||
removeParticleProcessor: function (processor)
|
||||
{
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
/**
|
||||
* @callback Phaser.Types.GameObjects.Particles.ParticleEmitterOps
|
||||
* @typedef {object} Phaser.Types.GameObjects.Particles.ParticleEmitterOps
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} accelerationX - The accelerationX EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} accelerationY - The accelerationY EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} alpha - The alpha EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} angle - The angle EmitterOp instance. This is an onEmit operator only.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} bounce - The bounce EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterColorOp} color - The color EmitterColorOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} delay - The delay EmitterOp instance. This is an onEmit operator only.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} hold - The hold EmitterOp instance. This is an onEmit operator only.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} lifespan - The lifespan EmitterOp instance. This is an onEmit operator only.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} maxVelocityX - The maxVelocityX EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} maxVelocityY - The maxVelocityY EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} moveToX - The moveToX EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} moveToY - The moveToY EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} quantity - The quantity EmitterOp instance. This is an onEmit operator only.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} rotate - The rotate EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} scaleX - The scaleX EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} scaleY - The scaleY EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} speedX - The speedX EmitterOp instance. This is an onEmit operator only.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} speedY - The speedY EmitterOp instance. This is an onEmit operator only.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} tint - The tint EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} x - The x EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @param {Phaser.GameObjects.Particles.EmitterOp} y - The y EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} accelerationX - The accelerationX EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} accelerationY - The accelerationY EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} alpha - The alpha EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} angle - The angle EmitterOp instance. This is an onEmit operator only.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} bounce - The bounce EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterColorOp} color - The color EmitterColorOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} delay - The delay EmitterOp instance. This is an onEmit operator only.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} hold - The hold EmitterOp instance. This is an onEmit operator only.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} lifespan - The lifespan EmitterOp instance. This is an onEmit operator only.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} maxVelocityX - The maxVelocityX EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} maxVelocityY - The maxVelocityY EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} moveToX - The moveToX EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} moveToY - The moveToY EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} quantity - The quantity EmitterOp instance. This is an onEmit operator only.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} rotate - The rotate EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} scaleX - The scaleX EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} scaleY - The scaleY EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} speedX - The speedX EmitterOp instance. This is an onEmit operator only.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} speedY - The speedY EmitterOp instance. This is an onEmit operator only.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} tint - The tint EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} x - The x EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
* @property {Phaser.GameObjects.Particles.EmitterOp} y - The y EmitterOp instance. This is an onEmit and onUpdate operator.
|
||||
*/
|
||||
|
|
742
src/gameobjects/plane/Plane.js
Normal file
742
src/gameobjects/plane/Plane.js
Normal file
|
@ -0,0 +1,742 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013-2023 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var AnimationState = require('../../animations/AnimationState');
|
||||
var Class = require('../../utils/Class');
|
||||
var GenerateGridVerts = require('../../geom/mesh/GenerateGridVerts');
|
||||
var IntegerToRGB = require('../../display/color/IntegerToRGB');
|
||||
var Mesh = require('../mesh/Mesh');
|
||||
var UUID = require('../../utils/string/UUID');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A Plane Game Object.
|
||||
*
|
||||
* The Plane Game Object is a helper class that takes the Mesh Game Object and extends it,
|
||||
* allowing for fast and easy creation of Planes. A Plane is a one-sided grid of cells,
|
||||
* where you specify the number of cells in each dimension. The Plane can have a texture
|
||||
* that is either repeated (tiled) across each cell, or applied to the full Plane.
|
||||
*
|
||||
* The Plane can then be manipulated in 3D space, with rotation across all 3 axis.
|
||||
*
|
||||
* This allows you to create effects not possible with regular Sprites, such as perspective
|
||||
* distortion. You can also adjust the vertices on a per-vertex basis. Plane data becomes
|
||||
* part of the WebGL batch, just like standard Sprites, so doesn't introduce any additional
|
||||
* shader overhead. Because the Plane just generates vertices into the WebGL batch, like any
|
||||
* other Sprite, you can use all of the common Game Object components on a Plane too,
|
||||
* such as a custom pipeline, mask, blend mode or texture.
|
||||
*
|
||||
* You can use the `uvScroll` and `uvScale` methods to adjust the placement and scaling
|
||||
* of the texture if this Plane is using a single texture, and not a frame from a texture
|
||||
* atlas or sprite sheet.
|
||||
*
|
||||
* The Plane Game Object also has the Animation component, allowing you to play animations
|
||||
* across the Plane just as you would with a Sprite.
|
||||
*
|
||||
* While a Plane cannot be enabled for input it does have the methods `hasFaceAt` and
|
||||
* `getFaceAt` which can be used with Pointer coordinates to detect if they have clicked
|
||||
* on Plane face, or not.
|
||||
*
|
||||
* Note that the Plane object is WebGL only and does not have a Canvas counterpart.
|
||||
*
|
||||
* The Plane origin is always 0.5 x 0.5 and cannot be changed.
|
||||
*
|
||||
* @class Plane
|
||||
* @extends Phaser.GameObjects.Mesh
|
||||
* @memberof Phaser.GameObjects
|
||||
* @constructor
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {Phaser.Scene} scene - The Scene to which this Plane belongs. A Plane can only belong to one Scene at a time.
|
||||
* @param {number} [x] - The horizontal position of this Plane in the world.
|
||||
* @param {number} [y] - The vertical position of this Plane in the world.
|
||||
* @param {string|Phaser.Textures.Texture} [texture] - The key, or instance of the Texture this Plane will use to render with, as stored in the Texture Manager.
|
||||
* @param {string|number} [frame] - An optional frame from the Texture this Plane is rendering with.
|
||||
* @param {number} [width=8] - The width of this Plane, in cells, not pixels.
|
||||
* @param {number} [height=8] - The height of this Plane, in cells, not pixels.
|
||||
* @param {boolean} [tile=false] - Is the texture tiled? I.e. repeated across each cell.
|
||||
*/
|
||||
var Plane = new Class({
|
||||
|
||||
Extends: Mesh,
|
||||
|
||||
initialize:
|
||||
|
||||
function Plane (scene, x, y, texture, frame, width, height, tile)
|
||||
{
|
||||
if (!texture) { texture = '__DEFAULT'; }
|
||||
|
||||
Mesh.call(this, scene, x, y, texture, frame);
|
||||
|
||||
this.type = 'Plane';
|
||||
|
||||
/**
|
||||
* The Animation State component of this Sprite.
|
||||
*
|
||||
* This component provides features to apply animations to this Sprite.
|
||||
* It is responsible for playing, loading, queuing animations for later playback,
|
||||
* mixing between animations and setting the current animation frame to this Sprite.
|
||||
*
|
||||
* @name Phaser.GameObjects.Plane#anims
|
||||
* @type {Phaser.Animations.AnimationState}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.anims = new AnimationState(this);
|
||||
|
||||
/**
|
||||
* The width of this Plane in cells, not pixels.
|
||||
*
|
||||
* This value is read-only. To adjust it, see the `setGridSize` method.
|
||||
*
|
||||
* @name Phaser.GameObjects.Plane#gridWidth
|
||||
* @type {number}
|
||||
* @readonly
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.gridWidth;
|
||||
|
||||
/**
|
||||
* The height of this Plane in cells, not pixels.
|
||||
*
|
||||
* This value is read-only. To adjust it, see the `setGridSize` method.
|
||||
*
|
||||
* @name Phaser.GameObjects.Plane#gridHeight
|
||||
* @type {number}
|
||||
* @readonly
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.gridHeight;
|
||||
|
||||
/**
|
||||
* Is the texture of this Plane tiled across all cells, or not?
|
||||
*
|
||||
* This value is read-only. To adjust it, see the `setGridSize` method.
|
||||
*
|
||||
* @name Phaser.GameObjects.Plane#isTiled
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.isTiled;
|
||||
|
||||
/**
|
||||
* If this Plane has a checkboard texture, this is a reference to
|
||||
* the WebGLTexture being used. Otherwise, it's null.
|
||||
*
|
||||
* @name Phaser.GameObjects.Plane#_checkerboard
|
||||
* @type {?WebGLTexture}
|
||||
* @private
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this._checkerboard = null;
|
||||
|
||||
this.hideCCW = false;
|
||||
|
||||
this.setGridSize(width, height, tile);
|
||||
this.setSizeToFrame(false);
|
||||
this.setViewHeight();
|
||||
},
|
||||
|
||||
/**
|
||||
* Modifies the layout of this Plane by adjusting the grid dimensions to the
|
||||
* given width and height. The values are given in cells, not pixels.
|
||||
*
|
||||
* The `tile` parameter allows you to control if the texture is tiled, or
|
||||
* applied across the entire Plane? A tiled texture will repeat with one
|
||||
* iteration per cell. A non-tiled texture will be applied across the whole
|
||||
* Plane.
|
||||
*
|
||||
* Note that if this Plane is using a single texture, not from a texture atlas
|
||||
* or sprite sheet, then you can use the `Plane.uvScale` method to have much
|
||||
* more fine-grained control over the texture tiling.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#preDestroy
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} [width=8] - The width of this Plane, in cells, not pixels.
|
||||
* @param {number} [height=8] - The height of this Plane, in cells, not pixels.
|
||||
* @param {boolean} [tile=false] - Is the texture tiled? I.e. repeated across each cell.
|
||||
*/
|
||||
setGridSize: function (width, height, tile)
|
||||
{
|
||||
if (width === undefined) { width = 8; }
|
||||
if (height === undefined) { height = 8; }
|
||||
if (tile === undefined) { tile = false; }
|
||||
|
||||
var flipY = false;
|
||||
|
||||
if (tile)
|
||||
{
|
||||
flipY = true;
|
||||
}
|
||||
|
||||
this.gridWidth = width;
|
||||
this.gridHeight = height;
|
||||
this.isTiled = tile;
|
||||
|
||||
this.clear();
|
||||
|
||||
GenerateGridVerts({
|
||||
mesh: this,
|
||||
widthSegments: width,
|
||||
heightSegments: height,
|
||||
isOrtho: false,
|
||||
tile: tile,
|
||||
flipY: flipY
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* An internal method that resets the perspective projection for this Plane
|
||||
* when it changes texture or frame, and also resets the cell UV coordinates,
|
||||
* if required.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#setSizeToFrame
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {boolean} [resetUV=true] - Reset all of the cell UV coordinates?
|
||||
*/
|
||||
setSizeToFrame: function (resetUV)
|
||||
{
|
||||
if (resetUV === undefined) { resetUV = true; }
|
||||
|
||||
var frame = this.frame;
|
||||
|
||||
this.setPerspective(this.width / frame.width, this.height / frame.height);
|
||||
|
||||
if (this._checkerboard && this._checkerboard !== this.texture)
|
||||
{
|
||||
this.removeCheckerboard();
|
||||
}
|
||||
|
||||
if (!resetUV)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset UV coordinates if frame has changed
|
||||
|
||||
var gridX = this.gridWidth;
|
||||
var gridY = this.gridHeight;
|
||||
|
||||
var verts = this.vertices;
|
||||
|
||||
var frameU0 = frame.u0;
|
||||
var frameU1 = frame.u1;
|
||||
var frameV0 = frame.v0;
|
||||
var frameV1 = frame.v1;
|
||||
|
||||
var x;
|
||||
var y;
|
||||
var i = 0;
|
||||
|
||||
if (this.isTiled)
|
||||
{
|
||||
// flipY
|
||||
frameV0 = frame.v1;
|
||||
frameV1 = frame.v0;
|
||||
|
||||
for (y = 0; y < gridY; y++)
|
||||
{
|
||||
for (x = 0; x < gridX; x++)
|
||||
{
|
||||
verts[i++].setUVs(frameU0, frameV1);
|
||||
verts[i++].setUVs(frameU0, frameV0);
|
||||
verts[i++].setUVs(frameU1, frameV1);
|
||||
verts[i++].setUVs(frameU0, frameV0);
|
||||
verts[i++].setUVs(frameU1, frameV0);
|
||||
verts[i++].setUVs(frameU1, frameV1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var gridX1 = gridX + 1;
|
||||
var gridY1 = gridY + 1;
|
||||
|
||||
var frameU = frameU1 - frameU0;
|
||||
var frameV = frameV1 - frameV0;
|
||||
|
||||
var uvs = [];
|
||||
|
||||
for (y = 0; y < gridY1; y++)
|
||||
{
|
||||
for (x = 0; x < gridX1; x++)
|
||||
{
|
||||
var tu = frameU0 + frameU * (x / gridX);
|
||||
var tv = frameV0 + frameV * (y / gridY);
|
||||
|
||||
uvs.push(tu, tv);
|
||||
}
|
||||
}
|
||||
|
||||
for (y = 0; y < gridY; y++)
|
||||
{
|
||||
for (x = 0; x < gridX; x++)
|
||||
{
|
||||
var a = (x + gridX1 * y) * 2;
|
||||
var b = (x + gridX1 * (y + 1)) * 2;
|
||||
var c = ((x + 1) + gridX1 * (y + 1)) * 2;
|
||||
var d = ((x + 1) + gridX1 * y) * 2;
|
||||
|
||||
verts[i++].setUVs(uvs[a], uvs[a + 1]);
|
||||
verts[i++].setUVs(uvs[b], uvs[b + 1]);
|
||||
verts[i++].setUVs(uvs[d], uvs[d + 1]);
|
||||
verts[i++].setUVs(uvs[b], uvs[b + 1]);
|
||||
verts[i++].setUVs(uvs[c], uvs[c + 1]);
|
||||
verts[i++].setUVs(uvs[d], uvs[d + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the height of this Plane to match the given value, in pixels.
|
||||
*
|
||||
* This adjusts the `Plane.viewPosition.z` value to achieve this.
|
||||
*
|
||||
* If no `value` parameter is given, it will set the view height to match
|
||||
* that of the current texture frame the Plane is using.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#setViewHeight
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} [value] - The height, in pixels, to set this Plane view height to.
|
||||
*/
|
||||
setViewHeight: function (value)
|
||||
{
|
||||
if (value === undefined) { value = this.frame.height; }
|
||||
|
||||
var vFOV = this.fov * (Math.PI / 180);
|
||||
|
||||
this.viewPosition.z = (this.height / value) / (Math.tan(vFOV / 2));
|
||||
|
||||
this.dirtyCache[10] = 1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a checkerboard style texture, based on the given colors and alpha
|
||||
* values and applies it to this Plane, replacing any current texture it may
|
||||
* have.
|
||||
*
|
||||
* The colors are used in an alternating pattern, like a chess board.
|
||||
*
|
||||
* Calling this method generates a brand new 16x16 pixel WebGLTexture internally
|
||||
* and applies it to this Plane. While quite fast to do, you should still be
|
||||
* mindful of calling this method either extensively, or in tight parts of
|
||||
* your game.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#createCheckerboard
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} [color1=0xffffff] - The odd cell color, specified as a hex value.
|
||||
* @param {number} [color2=0x0000ff] - The even cell color, specified as a hex value.
|
||||
* @param {number} [alpha1=255] - The odd cell alpha value, specified as a number between 0 and 255.
|
||||
* @param {number} [alpha2=255] - The even cell alpha value, specified as a number between 0 and 255.
|
||||
* @param {number} [height=128] - The view height of the Plane after creation, in pixels.
|
||||
*/
|
||||
createCheckerboard: function (color1, color2, alpha1, alpha2, height)
|
||||
{
|
||||
if (color1 === undefined) { color1 = 0xffffff; }
|
||||
if (color2 === undefined) { color2 = 0x0000ff; }
|
||||
if (alpha1 === undefined) { alpha1 = 255; }
|
||||
if (alpha2 === undefined) { alpha2 = 255; }
|
||||
if (height === undefined) { height = 128; }
|
||||
|
||||
var gl = this.scene.sys.renderer.gl;
|
||||
|
||||
var glTexture = gl.createTexture();
|
||||
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
|
||||
gl.bindTexture(gl.TEXTURE_2D, glTexture);
|
||||
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
|
||||
// Let's assume 16x16 for our texture size and 8x8 cell size
|
||||
|
||||
var c1 = IntegerToRGB(color1);
|
||||
var c2 = IntegerToRGB(color2);
|
||||
|
||||
var colors = [];
|
||||
|
||||
for (var h = 0; h < 16; h++)
|
||||
{
|
||||
for (var w = 0; w < 16; w++)
|
||||
{
|
||||
if ((h < 8 && w < 8) || (h > 7 && w > 7))
|
||||
{
|
||||
colors.push(c1.r, c1.g, c1.b, alpha1);
|
||||
}
|
||||
else
|
||||
{
|
||||
colors.push(c2.r, c2.g, c2.b, alpha2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array(colors));
|
||||
|
||||
glTexture.isAlphaPremultiplied = true;
|
||||
glTexture.isRenderTexture = false;
|
||||
glTexture.width = 16;
|
||||
glTexture.height = 16;
|
||||
|
||||
var texture = this.scene.sys.textures.addGLTexture(UUID(), glTexture, 16, 16);
|
||||
|
||||
this.removeCheckerboard();
|
||||
|
||||
this._checkerboard = texture;
|
||||
|
||||
gl.bindTexture(gl.TEXTURE_2D, null);
|
||||
|
||||
this.setTexture(texture);
|
||||
|
||||
this.setSizeToFrame();
|
||||
|
||||
this.setViewHeight(height);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* If this Plane has a Checkerboard Texture, this method will destroy it
|
||||
* and reset the internal flag for it.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#removeCheckerboard
|
||||
* @since 3.60.0
|
||||
*/
|
||||
removeCheckerboard: function ()
|
||||
{
|
||||
if (this._checkerboard)
|
||||
{
|
||||
this._checkerboard.destroy();
|
||||
|
||||
this._checkerboard = null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Start playing the given animation on this Plane.
|
||||
*
|
||||
* Animations in Phaser can either belong to the global Animation Manager, or specifically to this Plane.
|
||||
*
|
||||
* The benefit of a global animation is that multiple Game Objects can all play the same animation, without
|
||||
* having to duplicate the data. You can just create it once and then play it on any animating Game Object.
|
||||
*
|
||||
* The following code shows how to create a global repeating animation. The animation will be created
|
||||
* from all of the frames within the sprite sheet that was loaded with the key 'muybridge':
|
||||
*
|
||||
* ```javascript
|
||||
* var config = {
|
||||
* key: 'run',
|
||||
* frames: 'muybridge',
|
||||
* frameRate: 15,
|
||||
* repeat: -1
|
||||
* };
|
||||
*
|
||||
* // This code should be run from within a Scene:
|
||||
* this.anims.create(config);
|
||||
* ```
|
||||
*
|
||||
* However, if you wish to create an animation that is unique to this Plane, and this Plane alone,
|
||||
* you can call the `Animation.create` method instead. It accepts the exact same parameters as when
|
||||
* creating a global animation, however the resulting data is kept locally in this Plane.
|
||||
*
|
||||
* With the animation created, either globally or locally, you can now play it on this Plane:
|
||||
*
|
||||
* ```javascript
|
||||
* const plane = this.add.plane(...);
|
||||
* plane.play('run');
|
||||
* ```
|
||||
*
|
||||
* Alternatively, if you wish to run it at a different frame rate for example, you can pass a config
|
||||
* object instead:
|
||||
*
|
||||
* ```javascript
|
||||
* const plane = this.add.plane(...);
|
||||
* plane.play({ key: 'run', frameRate: 24 });
|
||||
* ```
|
||||
*
|
||||
* When playing an animation on a Plane it will first check to see if it can find a matching key
|
||||
* locally within the Plane. If it can, it will play the local animation. If not, it will then
|
||||
* search the global Animation Manager and look for it there.
|
||||
*
|
||||
* If you need a Plane to be able to play both local and global animations, make sure they don't
|
||||
* have conflicting keys.
|
||||
*
|
||||
* See the documentation for the `PlayAnimationConfig` config object for more details about this.
|
||||
*
|
||||
* Also, see the documentation in the Animation Manager for further details on creating animations.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#play
|
||||
* @fires Phaser.Animations.Events#ANIMATION_START
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
|
||||
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
|
||||
*
|
||||
* @return {this} This Game Object.
|
||||
*/
|
||||
play: function (key, ignoreIfPlaying)
|
||||
{
|
||||
return this.anims.play(key, ignoreIfPlaying);
|
||||
},
|
||||
|
||||
/**
|
||||
* Start playing the given animation on this Plane, in reverse.
|
||||
*
|
||||
* Animations in Phaser can either belong to the global Animation Manager, or specifically to a Game Object.
|
||||
*
|
||||
* The benefit of a global animation is that multiple Game Objects can all play the same animation, without
|
||||
* having to duplicate the data. You can just create it once and then play it on any animating Game Object.
|
||||
*
|
||||
* The following code shows how to create a global repeating animation. The animation will be created
|
||||
* from all of the frames within the sprite sheet that was loaded with the key 'muybridge':
|
||||
*
|
||||
* ```javascript
|
||||
* var config = {
|
||||
* key: 'run',
|
||||
* frames: 'muybridge',
|
||||
* frameRate: 15,
|
||||
* repeat: -1
|
||||
* };
|
||||
*
|
||||
* // This code should be run from within a Scene:
|
||||
* this.anims.create(config);
|
||||
* ```
|
||||
*
|
||||
* However, if you wish to create an animation that is unique to this Game Object, and this Game Object alone,
|
||||
* you can call the `Animation.create` method instead. It accepts the exact same parameters as when
|
||||
* creating a global animation, however the resulting data is kept locally in this Game Object.
|
||||
*
|
||||
* With the animation created, either globally or locally, you can now play it on this Game Object:
|
||||
*
|
||||
* ```javascript
|
||||
* const plane = this.add.plane(...);
|
||||
* plane.playReverse('run');
|
||||
* ```
|
||||
*
|
||||
* Alternatively, if you wish to run it at a different frame rate, for example, you can pass a config
|
||||
* object instead:
|
||||
*
|
||||
* ```javascript
|
||||
* const plane = this.add.plane(...);
|
||||
* plane.playReverse({ key: 'run', frameRate: 24 });
|
||||
* ```
|
||||
*
|
||||
* When playing an animation on a Game Object it will first check to see if it can find a matching key
|
||||
* locally within the Game Object. If it can, it will play the local animation. If not, it will then
|
||||
* search the global Animation Manager and look for it there.
|
||||
*
|
||||
* If you need a Game Object to be able to play both local and global animations, make sure they don't
|
||||
* have conflicting keys.
|
||||
*
|
||||
* See the documentation for the `PlayAnimationConfig` config object for more details about this.
|
||||
*
|
||||
* Also, see the documentation in the Animation Manager for further details on creating animations.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#playReverse
|
||||
* @fires Phaser.Animations.Events#ANIMATION_START
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
|
||||
* @param {boolean} [ignoreIfPlaying=false] - If an animation is already playing then ignore this call.
|
||||
*
|
||||
* @return {this} This Game Object.
|
||||
*/
|
||||
playReverse: function (key, ignoreIfPlaying)
|
||||
{
|
||||
return this.anims.playReverse(key, ignoreIfPlaying);
|
||||
},
|
||||
|
||||
/**
|
||||
* Waits for the specified delay, in milliseconds, then starts playback of the given animation.
|
||||
*
|
||||
* If the animation _also_ has a delay value set in its config, it will be **added** to the delay given here.
|
||||
*
|
||||
* If an animation is already running and a new animation is given to this method, it will wait for
|
||||
* the given delay before starting the new animation.
|
||||
*
|
||||
* If no animation is currently running, the given one begins after the delay.
|
||||
*
|
||||
* When playing an animation on a Game Object it will first check to see if it can find a matching key
|
||||
* locally within the Game Object. If it can, it will play the local animation. If not, it will then
|
||||
* search the global Animation Manager and look for it there.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#playAfterDelay
|
||||
* @fires Phaser.Animations.Events#ANIMATION_START
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
|
||||
* @param {number} delay - The delay, in milliseconds, to wait before starting the animation playing.
|
||||
*
|
||||
* @return {this} This Game Object.
|
||||
*/
|
||||
playAfterDelay: function (key, delay)
|
||||
{
|
||||
return this.anims.playAfterDelay(key, delay);
|
||||
},
|
||||
|
||||
/**
|
||||
* Waits for the current animation to complete the `repeatCount` number of repeat cycles, then starts playback
|
||||
* of the given animation.
|
||||
*
|
||||
* You can use this to ensure there are no harsh jumps between two sets of animations, i.e. going from an
|
||||
* idle animation to a walking animation, by making them blend smoothly into each other.
|
||||
*
|
||||
* If no animation is currently running, the given one will start immediately.
|
||||
*
|
||||
* When playing an animation on a Game Object it will first check to see if it can find a matching key
|
||||
* locally within the Game Object. If it can, it will play the local animation. If not, it will then
|
||||
* search the global Animation Manager and look for it there.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#playAfterRepeat
|
||||
* @fires Phaser.Animations.Events#ANIMATION_START
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {(string|Phaser.Animations.Animation|Phaser.Types.Animations.PlayAnimationConfig)} key - The string-based key of the animation to play, or an Animation instance, or a `PlayAnimationConfig` object.
|
||||
* @param {number} [repeatCount=1] - How many times should the animation repeat before the next one starts?
|
||||
*
|
||||
* @return {this} This Game Object.
|
||||
*/
|
||||
playAfterRepeat: function (key, repeatCount)
|
||||
{
|
||||
return this.anims.playAfterRepeat(key, repeatCount);
|
||||
},
|
||||
|
||||
/**
|
||||
* Immediately stops the current animation from playing and dispatches the `ANIMATION_STOP` events.
|
||||
*
|
||||
* If no animation is playing, no event will be dispatched.
|
||||
*
|
||||
* If there is another animation queued (via the `chain` method) then it will start playing immediately.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#stop
|
||||
* @fires Phaser.Animations.Events#ANIMATION_STOP
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @return {this} This Game Object.
|
||||
*/
|
||||
stop: function ()
|
||||
{
|
||||
return this.anims.stop();
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops the current animation from playing after the specified time delay, given in milliseconds.
|
||||
*
|
||||
* It then dispatches the `ANIMATION_STOP` event.
|
||||
*
|
||||
* If no animation is running, no events will be dispatched.
|
||||
*
|
||||
* If there is another animation in the queue (set via the `chain` method) then it will start playing,
|
||||
* when the current one stops.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#stopAfterDelay
|
||||
* @fires Phaser.Animations.Events#ANIMATION_STOP
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} delay - The number of milliseconds to wait before stopping this animation.
|
||||
*
|
||||
* @return {this} This Game Object.
|
||||
*/
|
||||
stopAfterDelay: function (delay)
|
||||
{
|
||||
return this.anims.stopAfterDelay(delay);
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops the current animation from playing after the given number of repeats.
|
||||
*
|
||||
* It then dispatches the `ANIMATION_STOP` event.
|
||||
*
|
||||
* If no animation is running, no events will be dispatched.
|
||||
*
|
||||
* If there is another animation in the queue (set via the `chain` method) then it will start playing,
|
||||
* when the current one stops.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#stopAfterRepeat
|
||||
* @fires Phaser.Animations.Events#ANIMATION_STOP
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} [repeatCount=1] - How many times should the animation repeat before stopping?
|
||||
*
|
||||
* @return {this} This Game Object.
|
||||
*/
|
||||
stopAfterRepeat: function (repeatCount)
|
||||
{
|
||||
return this.anims.stopAfterRepeat(repeatCount);
|
||||
},
|
||||
|
||||
/**
|
||||
* Stops the current animation from playing when it next sets the given frame.
|
||||
* If this frame doesn't exist within the animation it will not stop it from playing.
|
||||
*
|
||||
* It then dispatches the `ANIMATION_STOP` event.
|
||||
*
|
||||
* If no animation is running, no events will be dispatched.
|
||||
*
|
||||
* If there is another animation in the queue (set via the `chain` method) then it will start playing,
|
||||
* when the current one stops.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#stopOnFrame
|
||||
* @fires Phaser.Animations.Events#ANIMATION_STOP
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {Phaser.Animations.AnimationFrame} frame - The frame to check before stopping this animation.
|
||||
*
|
||||
* @return {this} This Game Object.
|
||||
*/
|
||||
stopOnFrame: function (frame)
|
||||
{
|
||||
return this.anims.stopOnFrame(frame);
|
||||
},
|
||||
|
||||
/**
|
||||
* Runs the preUpdate for this Plane, which will check its Animation State,
|
||||
* if one is playing, and refresh view / model matrices, if updated.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#preUpdate
|
||||
* @protected
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} time - The current timestamp.
|
||||
* @param {number} delta - The delta time, in ms, elapsed since the last frame.
|
||||
*/
|
||||
preUpdate: function (time, delta)
|
||||
{
|
||||
Mesh.prototype.preUpdate.call(this, time, delta);
|
||||
|
||||
this.anims.update(time, delta);
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles the pre-destroy step for the Plane, which removes the vertices and debug callbacks.
|
||||
*
|
||||
* @method Phaser.GameObjects.Plane#preDestroy
|
||||
* @private
|
||||
* @since 3.60.0
|
||||
*/
|
||||
preDestroy: function ()
|
||||
{
|
||||
this.clear();
|
||||
this.removeCheckerboard();
|
||||
|
||||
this.anims.destroy();
|
||||
|
||||
this.anims = undefined;
|
||||
|
||||
this.debugCallback = null;
|
||||
this.debugGraphic = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Plane;
|
62
src/gameobjects/plane/PlaneCreator.js
Normal file
62
src/gameobjects/plane/PlaneCreator.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013-2023 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var BuildGameObject = require('../BuildGameObject');
|
||||
var BuildGameObjectAnimation = require('../BuildGameObjectAnimation');
|
||||
var GameObjectCreator = require('../GameObjectCreator');
|
||||
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
|
||||
var GetValue = require('../../utils/object/GetValue');
|
||||
var Plane = require('./Plane');
|
||||
|
||||
/**
|
||||
* Creates a new Plane Game Object and returns it.
|
||||
*
|
||||
* Note: This method will only be available if the Plane Game Object and WebGL support have been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectCreator#plane
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {Phaser.Types.GameObjects.Plane.PlaneConfig} config - The configuration object this Game Object will use to create itself.
|
||||
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Plane} The Game Object that was created.
|
||||
*/
|
||||
GameObjectCreator.register('plane', function (config, addToScene)
|
||||
{
|
||||
if (config === undefined) { config = {}; }
|
||||
|
||||
var key = GetAdvancedValue(config, 'key', null);
|
||||
var frame = GetAdvancedValue(config, 'frame', null);
|
||||
var width = GetValue(config, 'width', 8);
|
||||
var height = GetValue(config, 'height', 8);
|
||||
var tile = GetValue(config, 'tile', false);
|
||||
|
||||
var plane = new Plane(this.scene, 0, 0, key, frame, width, height, tile);
|
||||
|
||||
if (addToScene !== undefined)
|
||||
{
|
||||
config.add = addToScene;
|
||||
}
|
||||
|
||||
var checkerboard = GetValue(config, 'checkerboard', null);
|
||||
|
||||
if (checkerboard)
|
||||
{
|
||||
var color1 = GetValue(checkerboard, 'color1', 0xffffff);
|
||||
var color2 = GetValue(checkerboard, 'color2', 0x0000ff);
|
||||
var alpha1 = GetValue(checkerboard, 'alpha1', 255);
|
||||
var alpha2 = GetValue(checkerboard, 'alpha2', 255);
|
||||
var checkheight = GetValue(checkerboard, 'height', 128);
|
||||
|
||||
plane.createCheckerboard(color1, color2, alpha1, alpha2, checkheight);
|
||||
}
|
||||
|
||||
BuildGameObject(this.scene, plane, config);
|
||||
|
||||
BuildGameObjectAnimation(plane, config);
|
||||
|
||||
return plane;
|
||||
});
|
31
src/gameobjects/plane/PlaneFactory.js
Normal file
31
src/gameobjects/plane/PlaneFactory.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013-2023 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
var Plane = require('./Plane');
|
||||
var GameObjectFactory = require('../GameObjectFactory');
|
||||
|
||||
/**
|
||||
* Creates a new Plane Game Object and adds it to the Scene.
|
||||
*
|
||||
* Note: This method will only be available if the Plane Game Object has been built into Phaser.
|
||||
*
|
||||
* @method Phaser.GameObjects.GameObjectFactory#plane
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} [x] - The horizontal position of this Plane in the world.
|
||||
* @param {number} [y] - The vertical position of this Plane in the world.
|
||||
* @param {string|Phaser.Textures.Texture} [texture] - The key, or instance of the Texture this Plane will use to render with, as stored in the Texture Manager.
|
||||
* @param {string|number} [frame] - An optional frame from the Texture this Plane is rendering with.
|
||||
* @param {number} [width=8] - The width of this Plane, in cells, not pixels.
|
||||
* @param {number} [height=8] - The height of this Plane, in cells, not pixels.
|
||||
* @param {boolean} [tile=false] - Is the texture tiled? I.e. repeated across each cell.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Plane} The Plane Game Object that was created.
|
||||
*/
|
||||
GameObjectFactory.register('plane', function (x, y, texture, frame, width, height, tile)
|
||||
{
|
||||
return this.displayList.add(new Plane(this.scene, x, y, texture, frame, width, height, tile));
|
||||
});
|
10
src/gameobjects/plane/typedefs/PlaneCheckerboardConfig.js
Normal file
10
src/gameobjects/plane/typedefs/PlaneCheckerboardConfig.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* @typedef {object} Phaser.Types.GameObjects.Plane.PlaneCheckerboardConfig
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @property {number} [color1=0xffffff] - The odd cell color, specified as a hex value.
|
||||
* @property {number} [color2=0x0000ff] - The even cell color, specified as a hex value.
|
||||
* @property {number} [alpha1=255] - The odd cell alpha value, specified as a number between 0 and 255.
|
||||
* @property {number} [alpha2=255] - The even cell alpha value, specified as a number between 0 and 255.
|
||||
* @property {number} [height=128] - The view height of the Plane after creation, in pixels.
|
||||
*/
|
12
src/gameobjects/plane/typedefs/PlaneConfig.js
Normal file
12
src/gameobjects/plane/typedefs/PlaneConfig.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* @typedef {object} Phaser.Types.GameObjects.Plane.PlaneConfig
|
||||
* @extends Phaser.Types.GameObjects.GameObjectConfig
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @property {(string|Phaser.Textures.Texture)} [key] - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager.
|
||||
* @property {(string|number)} [frame] - An optional frame from the Texture this Game Object is rendering with.
|
||||
* @property {number} [width=8] - The width of this Plane, in cells, not pixels.
|
||||
* @property {number} [height=8] - The height of this Plane, in cells, not pixels.
|
||||
* @property {boolean} [tile=false] - Is the texture tiled? I.e. repeated across each cell.
|
||||
* @property {Phaser.Types.GameObjects.Plane.PlaneCheckerboardConfig} [checkerboard] - Plane checkerboard configuration object.
|
||||
*/
|
9
src/gameobjects/plane/typedefs/index.js
Normal file
9
src/gameobjects/plane/typedefs/index.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013-2023 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @namespace Phaser.Types.GameObjects.Plane
|
||||
*/
|
|
@ -405,6 +405,75 @@ var Face = new Class({
|
|||
return !(bounds.right < camera.x || bounds.bottom < camera.y || bounds.x > cr || bounds.y > cb);
|
||||
},
|
||||
|
||||
/**
|
||||
* Translates the original UV positions of each vertex by the given amounts.
|
||||
*
|
||||
* The original properties `Vertex.u` and `Vertex.v`
|
||||
* remain unchanged, only the translated properties
|
||||
* `Vertex.tu` and `Vertex.tv`, as used in rendering,
|
||||
* are updated.
|
||||
*
|
||||
* @method Phaser.Geom.Mesh.Face#scrollUV
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} x - The amount to scroll the UV u coordinate by.
|
||||
* @param {number} y - The amount to scroll the UV v coordinate by.
|
||||
*
|
||||
* @return {this} This Face instance.
|
||||
*/
|
||||
scrollUV: function (x, y)
|
||||
{
|
||||
this.vertex1.scrollUV(x, y);
|
||||
this.vertex2.scrollUV(x, y);
|
||||
this.vertex3.scrollUV(x, y);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Scales the original UV values of each vertex by the given amounts.
|
||||
*
|
||||
* The original properties `Vertex.u` and `Vertex.v`
|
||||
* remain unchanged, only the translated properties
|
||||
* `Vertex.tu` and `Vertex.tv`, as used in rendering,
|
||||
* are updated.
|
||||
*
|
||||
* @method Phaser.Geom.Mesh.Face#scaleUV
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} x - The amount to scale the UV u coordinate by.
|
||||
* @param {number} y - The amount to scale the UV v coordinate by.
|
||||
*
|
||||
* @return {this} This Face instance.
|
||||
*/
|
||||
scaleUV: function (x, y)
|
||||
{
|
||||
this.vertex1.scaleUV(x, y);
|
||||
this.vertex2.scaleUV(x, y);
|
||||
this.vertex3.scaleUV(x, y);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the color value for each Vertex in this Face.
|
||||
*
|
||||
* @method Phaser.Geom.Mesh.Face#setColor
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} color - The color value for each vertex.
|
||||
*
|
||||
* @return {this} This Face instance.
|
||||
*/
|
||||
setColor: function (color)
|
||||
{
|
||||
this.vertex1.color = color;
|
||||
this.vertex2.color = color;
|
||||
this.vertex3.color = color;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Calls the `Vertex.update` method on each of the vertices. This populates them
|
||||
* with the new translated values, updating their `tx`, `ty` and `ta` properties.
|
||||
|
@ -420,6 +489,8 @@ var Face = new Class({
|
|||
* @param {number} e - The parent transform matrix data e component.
|
||||
* @param {number} f - The parent transform matrix data f component.
|
||||
* @param {boolean} roundPixels - Round the vertex position or not?
|
||||
*
|
||||
* @return {this} This Face instance.
|
||||
*/
|
||||
update: function (alpha, a, b, c, d, e, f, roundPixels)
|
||||
{
|
||||
|
|
|
@ -76,9 +76,16 @@ var GenerateGridVerts = function (config)
|
|||
tempRotation.set(rotateX, rotateY, rotateZ);
|
||||
tempMatrix.fromRotationXYTranslation(tempRotation, tempPosition, zIsUp);
|
||||
|
||||
var textureFrame;
|
||||
|
||||
if (!texture && mesh)
|
||||
{
|
||||
texture = mesh.texture;
|
||||
|
||||
if (!frame)
|
||||
{
|
||||
textureFrame = mesh.frame;
|
||||
}
|
||||
}
|
||||
else if (mesh && typeof(texture) === 'string')
|
||||
{
|
||||
|
@ -90,7 +97,10 @@ var GenerateGridVerts = function (config)
|
|||
return result;
|
||||
}
|
||||
|
||||
var textureFrame = texture.get(frame);
|
||||
if (!textureFrame)
|
||||
{
|
||||
textureFrame = texture.get(frame);
|
||||
}
|
||||
|
||||
// If the Mesh is ortho and no width / height is given, we'll default to texture sizes (if set!)
|
||||
if (!widthSet && isOrtho && texture && mesh)
|
||||
|
|
|
@ -165,11 +165,32 @@ var Vertex = new Class({
|
|||
* @since 3.50.0
|
||||
*/
|
||||
this.ta = 0;
|
||||
|
||||
/**
|
||||
* The translated uv u coordinate of this vertex.
|
||||
*
|
||||
* @name Phaser.Geom.Mesh.Vertex#tu
|
||||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.tu = u;
|
||||
|
||||
/**
|
||||
* The translated uv v coordinate of this vertex.
|
||||
*
|
||||
* @name Phaser.Geom.Mesh.Vertex#tv
|
||||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.tv = v;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the U and V properties.
|
||||
*
|
||||
* Also resets the translated uv properties, undoing any scale
|
||||
* or shift they may have had.
|
||||
*
|
||||
* @method Phaser.Geom.Mesh.Vertex#setUVs
|
||||
* @since 3.50.0
|
||||
*
|
||||
|
@ -183,6 +204,57 @@ var Vertex = new Class({
|
|||
this.u = u;
|
||||
this.v = v;
|
||||
|
||||
this.tu = u;
|
||||
this.tv = v;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Translates the original UV positions by the given amounts.
|
||||
*
|
||||
* The original properties `Vertex.u` and `Vertex.v`
|
||||
* remain unchanged, only the translated properties
|
||||
* `Vertex.tu` and `Vertex.tv`, as used in rendering,
|
||||
* are updated.
|
||||
*
|
||||
* @method Phaser.Geom.Mesh.Vertex#scrollUV
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} x - The amount to scroll the UV u coordinate by.
|
||||
* @param {number} y - The amount to scroll the UV v coordinate by.
|
||||
*
|
||||
* @return {this} This Vertex.
|
||||
*/
|
||||
scrollUV: function (x, y)
|
||||
{
|
||||
this.tu += x;
|
||||
this.tv += y;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Scales the original UV values by the given amounts.
|
||||
*
|
||||
* The original properties `Vertex.u` and `Vertex.v`
|
||||
* remain unchanged, only the translated properties
|
||||
* `Vertex.tu` and `Vertex.tv`, as used in rendering,
|
||||
* are updated.
|
||||
*
|
||||
* @method Phaser.Geom.Mesh.Vertex#scaleUV
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {number} x - The amount to scale the UV u coordinate by.
|
||||
* @param {number} y - The amount to scale the UV v coordinate by.
|
||||
*
|
||||
* @return {this} This Vertex.
|
||||
*/
|
||||
scaleUV: function (x, y)
|
||||
{
|
||||
this.tu = this.u * x;
|
||||
this.tv = this.v * y;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
@ -322,8 +394,8 @@ var Vertex = new Class({
|
|||
{
|
||||
F32[++offset] = this.tx;
|
||||
F32[++offset] = this.ty;
|
||||
F32[++offset] = this.u;
|
||||
F32[++offset] = this.v;
|
||||
F32[++offset] = this.tu;
|
||||
F32[++offset] = this.tv;
|
||||
F32[++offset] = textureUnit;
|
||||
F32[++offset] = tintEffect;
|
||||
U32[++offset] = Utils.getTintAppendFloatAlpha(this.color, this.ta);
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
*/
|
||||
var Wrap = function (value, min, max)
|
||||
{
|
||||
if (value >= min && value <= max)
|
||||
{
|
||||
// Skip modulo if already in range
|
||||
return value;
|
||||
}
|
||||
|
||||
var range = max - min;
|
||||
|
||||
return (min + ((((value - min) % range) + range) % range));
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @typedef {object} Phaser.Types.Physics.Matter.MatterWorldConfig
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @property {(Phaser.Types.Math.Vector2Like|boolean)} [gravity] - Sets {@link Phaser.Physics.Matter.World#gravity}. If `false` Gravity will be set to zero.
|
||||
* @property {Phaser.Types.Math.Vector2Like} [gravity] - Sets {@link Phaser.Physics.Matter.World#gravity}.
|
||||
* @property {(object|boolean)} [setBounds] - Should the world have bounds enabled by default?
|
||||
* @property {number} [setBounds.x=0] - The x coordinate of the world bounds.
|
||||
* @property {number} [setBounds.y=0] - The y coordinate of the world bounds.
|
||||
|
|
|
@ -10,9 +10,10 @@ var Clone = require('../utils/object/Clone');
|
|||
var EventEmitter = require('eventemitter3');
|
||||
var Events = require('./events');
|
||||
var GameEvents = require('../core/events');
|
||||
var NOOP = require('../utils/NOOP');
|
||||
var GetAll = require('../utils/array/GetAll');
|
||||
var GetFirst = require('../utils/array/GetFirst');
|
||||
var NOOP = require('../utils/NOOP');
|
||||
var Vector2 = require('../math/Vector2');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
|
@ -148,6 +149,20 @@ var BaseSoundManager = new Class({
|
|||
*/
|
||||
this.unlocked = false;
|
||||
|
||||
/**
|
||||
* The Spatial Audio listener position.
|
||||
*
|
||||
* Only available with WebAudio.
|
||||
*
|
||||
* You can modify the x/y properties of this Vec2 directly to
|
||||
* adjust the listener position within the game world.
|
||||
*
|
||||
* @name Phaser.Sound.BaseSoundManager#listenerPosition
|
||||
* @type {Phaser.Math.Vector2}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.listenerPosition = new Vector2();
|
||||
|
||||
game.events.on(GameEvents.BLUR, this.onGameBlur, this);
|
||||
game.events.on(GameEvents.FOCUS, this.onGameFocus, this);
|
||||
game.events.on(GameEvents.PRE_STEP, this.update, this);
|
||||
|
@ -453,16 +468,21 @@ var BaseSoundManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Sets the destination for the spatial sound.
|
||||
* Currently only WebAudio is supported.
|
||||
* Sets the X and Y position of the Spatial Audio listener on this Web Audios context.
|
||||
*
|
||||
* @method Phaser.Sound.BaseSoundManager#setAudioDestination
|
||||
* @override
|
||||
* If you call this method with no parameters it will default to the center-point of
|
||||
* the game canvas. Depending on the type of game you're making, you may need to call
|
||||
* this method constantly to reset the listener position as the camera scrolls.
|
||||
*
|
||||
* Calling this method does nothing on HTML5Audio.
|
||||
*
|
||||
* @method Phaser.Sound.BaseSoundManager#setListenerPosition
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {Phaser.Types.Sound.SpatialSoundConfig|object} [destination] - An object with x and y fields
|
||||
* @param {number} [x] - The x position of the Spatial Audio listener.
|
||||
* @param {number} [y] - The y position of the Spatial Audio listener.
|
||||
*/
|
||||
setAudioDestination: NOOP,
|
||||
setListenerPosition: NOOP,
|
||||
|
||||
/**
|
||||
* Stops all the sounds in the game.
|
||||
|
@ -622,7 +642,7 @@ var BaseSoundManager = new Class({
|
|||
|
||||
this.sounds.length = 0;
|
||||
this.sounds = null;
|
||||
|
||||
this.listenerPosition = null;
|
||||
this.game = null;
|
||||
},
|
||||
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
/**
|
||||
* Config object containing settings for the source of the sound.
|
||||
* Config object containing settings for the source of the spatial sound.
|
||||
*
|
||||
* See https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Web_audio_spatialization_basics
|
||||
*
|
||||
* @typedef {object} Phaser.Types.Sound.SpatialSoundConfig
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @property {number} [x=0] - X coordinate for the source of the sound.
|
||||
* @property {number} [y=0] - Y coordinate for the source of the sound.
|
||||
* @property {number} [z=0] - Z coordinate for the source of the sound.
|
||||
* @property {('equalpower'|'HRTF')} [panningModel='equalpower'] - The spacialization algorithm that's used to position the audio in 3D space.
|
||||
* @property {('linear'|'inverse'|'exponential')} [distanceModel='inverse'] - Different algorithms which are used to reduce the volume of the audio source as it moves away from the listener.
|
||||
* @property {number} [orientationX=0] - X orientation of the sound.
|
||||
* @property {number} [orientationY=0] - Y orientation of the sound.
|
||||
* @property {number} [orientationZ=-1.0] - Z orientation of the sound.
|
||||
* @property {number} [refDistance=1] - Used by the distance models.
|
||||
* @property {number} [maxDistance =10000] - Maximum distance between the source and the listener.
|
||||
* @property {number} [rolloffFactor=1] - How quickly the volume is reduced as the panner moves away from the listener.
|
||||
* @property {number} [coneInnerAngle=360] - Specifies where the sound emanates from.
|
||||
* @property {number} [coneOuterAngle=360] - Specifies where the volume starts to drop away.
|
||||
* @property {number} [coneOuterGain=0] - Specifies the amount volume is reduced by.
|
||||
|
||||
* @property {number} [x=0] - The horizontal position of the audio in a right-hand Cartesian coordinate system.
|
||||
* @property {number} [y=0] - The vertical position of the audio in a right-hand Cartesian coordinate system.
|
||||
* @property {number} [z=0] - Represents the longitudinal (back and forth) position of the audio in a right-hand Cartesian coordinate system.
|
||||
* @property {('equalpower'|'HRTF')} [panningModel='equalpower'] - An enumerated value determining which spatialization algorithm to use to position the audio in 3D space.
|
||||
* @property {('linear'|'inverse'|'exponential')} [distanceModel='inverse'] - Which algorithm to use to reduce the volume of the audio source as it moves away from the listener. Possible values are "linear", "inverse" and "exponential". The default value is "inverse".
|
||||
* @property {number} [orientationX=0] - The horizontal position of the audio source's vector in a right-hand Cartesian coordinate system.
|
||||
* @property {number} [orientationY=0] - The vertical position of the audio source's vector in a right-hand Cartesian coordinate system.
|
||||
* @property {number} [orientationZ=-1] - Represents the longitudinal (back and forth) position of the audio source's vector in a right-hand Cartesian coordinate system.
|
||||
* @property {number} [refDistance=1] - A double value representing the reference distance for reducing volume as the audio source moves further from the listener. For distances greater than this the volume will be reduced based on `rolloffFactor` and `distanceModel`.
|
||||
* @property {number} [maxDistance=10000] - The maximum distance between the audio source and the listener, after which the volume is not reduced any further.
|
||||
* @property {number} [rolloffFactor=1] - A double value describing how quickly the volume is reduced as the source moves away from the listener. This value is used by all distance models.
|
||||
* @property {number} [coneInnerAngle=360] - The angle, in degrees, of a cone inside of which there will be no volume reduction.
|
||||
* @property {number} [coneOuterAngle=0] - The angle, in degrees, of a cone outside of which the volume will be reduced by a constant value, defined by the `coneOuterGain` property.
|
||||
* @property {number} [coneOuterGain=0] - The amount of volume reduction outside the cone defined by the `coneOuterAngle` attribute. Its default value is 0, meaning that no sound can be heard.
|
||||
* @property {Phaser.Math.Vector2Like} [follow] - Set this Sound object to automatically track the x/y position of this object. Can be a Phaser Game Object, Vec2 or anything that exposes public x/y properties.
|
||||
*/
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
var BaseSound = require('../BaseSound');
|
||||
var Class = require('../../utils/Class');
|
||||
var Events = require('../events');
|
||||
var GetFastValue = require('../../utils/object/GetFastValue');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
|
@ -19,7 +20,7 @@ var Events = require('../events');
|
|||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Sound.WebAudioSoundManager} manager - Reference to the current sound manager instance.
|
||||
* @param {Phaser.Sound.WebAudioSoundManager} manager - Reference to the WebAudio Sound Manager that owns this Sound instance.
|
||||
* @param {string} key - Asset key for the sound.
|
||||
* @param {Phaser.Types.Sound.SoundConfig} [config={}] - An optional config object containing default sound settings.
|
||||
*/
|
||||
|
@ -97,6 +98,25 @@ var WebAudioSound = new Class({
|
|||
*/
|
||||
this.pannerNode = null;
|
||||
|
||||
/**
|
||||
* The Stereo Spatial Panner node.
|
||||
*
|
||||
* @name Phaser.Sound.WebAudioSound#spatialNode
|
||||
* @type {PannerNode}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.spatialNode = null;
|
||||
|
||||
/**
|
||||
* If the Spatial Panner node has been set to track a vector or
|
||||
* Game Object, this retains a reference to it.
|
||||
*
|
||||
* @name Phaser.Sound.WebAudioSound#spatialSource
|
||||
* @type {Phaser.Types.Math.Vector2Like}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.spatialSource = null;
|
||||
|
||||
/**
|
||||
* The time at which the sound should have started playback from the beginning.
|
||||
*
|
||||
|
@ -469,34 +489,108 @@ var WebAudioSound = new Class({
|
|||
});
|
||||
|
||||
var source = this.currentConfig.source;
|
||||
|
||||
if (source && this.manager.context.createPanner)
|
||||
{
|
||||
if (!this.manager.audioDestination)
|
||||
{
|
||||
// Set the position of the listener
|
||||
this.manager.setAudioDestination({ x: this.manager.game.config.width / 2, y: this.manager.game.config.height / 2 });
|
||||
}
|
||||
this.spatialNode.panningModel = source.panningModel || 'equalpower',
|
||||
this.spatialNode.distanceModel = source.distanceModel || 'inverse',
|
||||
this.spatialNode.positionX.value = source.x;
|
||||
this.spatialNode.positionY.value = source.y;
|
||||
this.spatialNode.positionZ.value = source.z || 0;
|
||||
this.spatialNode.orientationX.value = source.orientationX || 0;
|
||||
this.spatialNode.orientationY.value = source.orientationY || 0;
|
||||
this.spatialNode.orientationZ.value = source.orientationZ || -1.0;
|
||||
this.spatialNode.refDistance = source.refDistance || 1;
|
||||
this.spatialNode.maxDistance = source.maxDistance || 10000;
|
||||
this.spatialNode.rolloffFactor = source.rollOff || 1;
|
||||
this.spatialNode.coneInnerAngle = source.innerCone || 360;
|
||||
this.spatialNode.coneOuterAngle = source.outerCone || 360;
|
||||
this.spatialNode.coneOuterGain = source.outerGain || 0;
|
||||
var node = this.spatialNode;
|
||||
|
||||
this.spatialSource = source;
|
||||
node.panningModel = GetFastValue(source, 'panningModel', 'equalpower');
|
||||
node.distanceModel = GetFastValue(source, 'distanceModel', 'inverse');
|
||||
node.positionX.value = GetFastValue(source, 'x', 0);
|
||||
node.positionY.value = GetFastValue(source, 'y', 0);
|
||||
node.positionZ.value = GetFastValue(source, 'z', 0);
|
||||
node.orientationX.value = GetFastValue(source, 'orientationX', 0);
|
||||
node.orientationY.value = GetFastValue(source, 'orientationY', 0);
|
||||
node.orientationZ.value = GetFastValue(source, 'orientationZ', -1);
|
||||
node.refDistance = GetFastValue(source, 'refDistance', 1);
|
||||
node.maxDistance = GetFastValue(source, 'maxDistance', 10000);
|
||||
node.rolloffFactor = GetFastValue(source, 'rolloffFactor', 1);
|
||||
node.coneInnerAngle = GetFastValue(source, 'coneInnerAngle', 360);
|
||||
node.coneOuterAngle = GetFastValue(source, 'coneOuterAngle', 0);
|
||||
node.coneOuterGain = GetFastValue(source, 'coneOuterGain', 0);
|
||||
|
||||
this.spatialSource = GetFastValue(source, 'follow', null);
|
||||
}
|
||||
|
||||
BaseSound.prototype.applyConfig.call(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the x position of this Sound in Spatial Audio space.
|
||||
*
|
||||
* This only has any effect if the sound was created with a SpatialSoundConfig object.
|
||||
*
|
||||
* Also see the `WebAudioSoundManager.setListenerPosition` method.
|
||||
*
|
||||
* If you find that the sound becomes too quiet, too quickly, as it moves away from
|
||||
* the listener, then try different `refDistance` property values when configuring
|
||||
* the spatial sound.
|
||||
*
|
||||
* @name Phaser.Sound.WebAudioSound#x
|
||||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
x: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
if (this.spatialNode)
|
||||
{
|
||||
return this.spatialNode.positionX;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (this.spatialNode)
|
||||
{
|
||||
this.spatialNode.positionX.value = value;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the y position of this Sound in Spatial Audio space.
|
||||
*
|
||||
* This only has any effect if the sound was created with a SpatialSoundConfig object.
|
||||
*
|
||||
* Also see the `WebAudioSoundManager.setListenerPosition` method.
|
||||
*
|
||||
* If you find that the sound becomes too quiet, too quickly, as it moves away from
|
||||
* the listener, then try different `refDistance` property values when configuring
|
||||
* the spatial sound.
|
||||
*
|
||||
* @name Phaser.Sound.WebAudioSound#y
|
||||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
y: {
|
||||
|
||||
get: function ()
|
||||
{
|
||||
if (this.spatialNode)
|
||||
{
|
||||
return this.spatialNode.positionY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
|
||||
set: function (value)
|
||||
{
|
||||
if (this.spatialNode)
|
||||
{
|
||||
this.spatialNode.positionY.value = value;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update method called automatically by sound manager on every game step.
|
||||
*
|
||||
|
@ -584,6 +678,7 @@ var WebAudioSound = new Class({
|
|||
{
|
||||
this.spatialNode.disconnect();
|
||||
this.spatialNode = null;
|
||||
this.spatialSource = null;
|
||||
}
|
||||
|
||||
this.rateUpdates.length = 0;
|
||||
|
|
|
@ -271,20 +271,28 @@ var WebAudioSoundManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Sets the destination for the spatial sound.
|
||||
* Currently only WebAudio is supported.
|
||||
* Sets the X and Y position of the Spatial Audio listener on this Web Audios context.
|
||||
*
|
||||
* @method Phaser.Sound.BaseSoundManager#setAudioDestination
|
||||
* @override
|
||||
* If you call this method with no parameters it will default to the center-point of
|
||||
* the game canvas. Depending on the type of game you're making, you may need to call
|
||||
* this method constantly to reset the listener position as the camera scrolls.
|
||||
*
|
||||
* Calling this method does nothing on HTML5Audio.
|
||||
*
|
||||
* @method Phaser.Sound.WebAudioSoundManager#setListenerPosition
|
||||
* @since 3.60.0
|
||||
*
|
||||
* @param {Phaser.Types.Sound.SpatialSoundConfig|object} [destination] - An object with x and y fields
|
||||
* @param {number} [x] - The x position of the Spatial Audio listener.
|
||||
* @param {number} [y] - The y position of the Spatial Audio listener.
|
||||
*/
|
||||
setAudioDestination: function (destination)
|
||||
setListenerPosition: function (x, y)
|
||||
{
|
||||
if (x === undefined) { x = this.game.scale.width / 2; }
|
||||
if (y === undefined) { y = this.game.scale.height / 2; }
|
||||
|
||||
this.audioDestination = destination;
|
||||
this.listenerPosition.set(x, y);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -370,6 +378,7 @@ var WebAudioSoundManager = new Class({
|
|||
|
||||
/**
|
||||
* Update method called on every game step.
|
||||
*
|
||||
* Removes destroyed sounds and updates every active sound in the game.
|
||||
*
|
||||
* @method Phaser.Sound.WebAudioSoundManager#update
|
||||
|
@ -382,7 +391,9 @@ var WebAudioSoundManager = new Class({
|
|||
*/
|
||||
update: function (time, delta)
|
||||
{
|
||||
if (this.audioDestination)
|
||||
var listener = this.context.listener;
|
||||
|
||||
if (this.listenerPosition && listener)
|
||||
{
|
||||
var listener = this.context.listener;
|
||||
if (this.audioDestination.x && !isNaN(this.audioDestination.x) && this.audioDestination.x !== this._spatialx)
|
||||
|
|
|
@ -93,7 +93,7 @@ var SpriteSheetFromAtlas = function (texture, frame, config)
|
|||
var frameX = margin;
|
||||
var frameY = margin;
|
||||
var frameIndex = 0;
|
||||
var sourceIndex = frame.sourceIndex;
|
||||
var sourceIndex = 0;
|
||||
|
||||
for (var sheetY = 0; sheetY < column; sheetY++)
|
||||
{
|
||||
|
|
|
@ -56,6 +56,17 @@ var Clock = new Class({
|
|||
*/
|
||||
this.now = 0;
|
||||
|
||||
/**
|
||||
* The time the Clock (and Scene) started, in milliseconds.
|
||||
*
|
||||
* This can be compared to the `time` parameter passed to a Scene's `update` method.
|
||||
*
|
||||
* @name Phaser.Time.Clock#startTime
|
||||
* @type {number}
|
||||
* @since 3.60.0
|
||||
*/
|
||||
this.startTime = 0;
|
||||
|
||||
/**
|
||||
* The scale of the Clock's time delta.
|
||||
*
|
||||
|
@ -144,6 +155,8 @@ var Clock = new Class({
|
|||
*/
|
||||
start: function ()
|
||||
{
|
||||
this.startTime = this.systems.game.loop.time;
|
||||
|
||||
var eventEmitter = this.systems.events;
|
||||
|
||||
eventEmitter.on(SceneEvents.PRE_UPDATE, this.preUpdate, this);
|
||||
|
|
Loading…
Add table
Reference in a new issue