mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Merge branch 'master' into feature-multi-image-loader
This commit is contained in:
commit
ed51affded
60 changed files with 2134 additions and 980 deletions
24
CHANGELOG.md
24
CHANGELOG.md
|
@ -6,23 +6,43 @@
|
|||
|
||||
* The Phaser 3 Labs has gained a nifty 'search' feature box thanks to @NemoStein - it allows you to filter out the example categories.
|
||||
* We've added a Mask component, which is available on nearly all Game Objects. It includes the methods `setMask`, `clearMask`, `createBitmapMask` and `createGeometryMask`.
|
||||
* CanvasTexture is a new extension of the Texture object specifically created for when you've got a Canvas element as the backing source of the texture that you wish to draw to programmatically using the Canvas API. This was possible in previous versions, as a Texture object supported having a Canvas as its source, but we've streamlined the process and made it a lot easier for you to refresh the resulting WebGLTexture on the GPU. To create a CanvasTexture just call the `TextureManager.createCanvas` method as before, only this time you'll get a CanvasTexture back which has helper properties and methods. See the complete JSDocs for more details.
|
||||
|
||||
### Updates
|
||||
|
||||
* If you're using Webpack with Phaser you'll need to update your config to match our new one.
|
||||
* We've swapped use of the Webpack DefinePlugin so instead of setting a global flag for the compilation of the Canvas and WebGL renderers, we now use a typeof check instead. This means you should now be able to ingest the Phaser source more easily outside of Webpack without having to define any global vars first (thanks @tgrajewski)
|
||||
* Under Webpack we still use the raw-loader to import our shader source, but outside of Webpack we now use `require.extensions` to load the shader source via fs. This should allow you to bundle Phaser with packages other than Webpack more easily (thanks @tgrajewski)
|
||||
* The Texture Manager will now emit an `addtexture` event whenever you add a new texture to it, which includes when you load images files from the Loader (as it automatically populates the Texture Manager). Once you receive an `addtexture` event you know the image is loaded and the texture is safe to be applied to a Game Object.
|
||||
* The Texture Manager will now emit an `addtexture` event whenever you add a new texture to it, which includes when you load image files from the Loader (as it automatically populates the Texture Manager). Once you receive an `addtexture` event you know the image is loaded and the texture is safe to be applied to a Game Object.
|
||||
* BitmapMask and GeometryMask both have new `destroy` methods which clear their references, freeing them for gc.
|
||||
* CanvasPool has a new argument `selfParent` which allows the canvas itself to be the parent key, used for later removal.
|
||||
* Frame has a new method `setSize` which allows you to set the frame x, y, width and height and have it update all of the internal properties automatically. This is now called directly in the constructor.
|
||||
* When a TextureSource is destroyed if it's got a canvas texture it's removed from the CanvasPool.
|
||||
* TextureManager.checkKey will check if a texture key is in-use and log a console error if it is and then return a boolean. This is now used extensively internally to prevent you from adding textures that already exist into the manager. If you wish to just check if a key is in use without the error, use the `TextureManager.exists` method as before.
|
||||
* TextureManager.remove will allow you to remove a texture from the manager. The texture is destroyed and it emits a `removetexture` event.
|
||||
* TextureSource has a new property `renderer` as it's used a lot internally and is useful if you extend the class.
|
||||
* TextureSource will now remove its respective WebGLTexture from the renderer when destroyed.
|
||||
* TextureSource will now automatically create a glTexture from its canvas if using one.
|
||||
* WebGLRenderer will now remove a GL texture from its local `nativeTextures` array when you call the `deleteTexture` method.
|
||||
* The BaseCache has a new method `exists` that will return a boolean if an entry for the given key exists in the cache or not.
|
||||
* Loader.File has a new argument in its constructor which is an instance of the LoaderPlugin. It stores this in the `loader` property. It also has a new property `cache` which is a reference to the cache that the file type will be stored in.
|
||||
* Loader.File has a new method `hasCacheConflict` which checks if a key matching the one used by this file exists in the target Cache or not.
|
||||
* Loader.File has a new method `addToCache` which will add the file to its target cache and then emit a `filecomplete` event, passing its key and a reference to itself to the listener (thanks to @kalebwalton for a related PR)
|
||||
* LoaderPlugin has a new property `cacheManager` which is a reference to the global game cache and is used by the File Types.
|
||||
* LoaderPlugin has a new property `textureManager` which is a reference to the global Texture Manager and is used by the File Types.
|
||||
* LoaderPlugin will now check to see if loading a file would cache a cache conflict or not, and prevent it if it will.
|
||||
* LoaderPlugin now passes off processing of the final file data to the file itself, which will now self-add itself to its target cache.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* DataManagerPlugin would throw an error on Game.destroy if you had any Scenes in the Scene Manager had not been run. Fix #3596 (thanks @kuoruan)
|
||||
* If you created a Game with no Scenes defined, and then added one via `Game.scene.add` and passed in a data object, the data would be ignored when starting the Scene.
|
||||
|
||||
### Examples, Documentation and TypeScript
|
||||
|
||||
My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs:
|
||||
|
||||
@wtravO
|
||||
@wtravO @Fabadiculous @zilbuz @samme
|
||||
|
||||
## Version 3.6.0 - Asuna - 19th April 2018
|
||||
|
||||
|
|
17
src/cache/BaseCache.js
vendored
17
src/cache/BaseCache.js
vendored
|
@ -83,6 +83,7 @@ var BaseCache = new Class({
|
|||
|
||||
/**
|
||||
* Checks if this cache contains an item matching the given key.
|
||||
* This performs the same action as `BaseCache.exists`.
|
||||
*
|
||||
* @method Phaser.Cache.BaseCache#has
|
||||
* @since 3.0.0
|
||||
|
@ -96,6 +97,22 @@ var BaseCache = new Class({
|
|||
return this.entries.has(key);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if this cache contains an item matching the given key.
|
||||
* This performs the same action as `BaseCache.has` and is called directly by the Loader.
|
||||
*
|
||||
* @method Phaser.Cache.BaseCache#exists
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @param {string} key - The unique key of the item to be checked in this cache.
|
||||
*
|
||||
* @return {boolean} Returns `true` if the cache contains an item matching the given key, otherwise `false`.
|
||||
*/
|
||||
exists: function (key)
|
||||
{
|
||||
return this.entries.has(key);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets an item from this cache based on the given key.
|
||||
*
|
||||
|
|
|
@ -36,14 +36,16 @@ var CanvasPool = function ()
|
|||
* @param {integer} [width=1] - The width of the Canvas.
|
||||
* @param {integer} [height=1] - The height of the Canvas.
|
||||
* @param {integer} [canvasType=Phaser.CANVAS] - The type of the Canvas. Either `Phaser.CANVAS` or `Phaser.WEBGL`.
|
||||
* @param {boolean} [selfParent=false] - Use the generated Canvas element as the parent?
|
||||
*
|
||||
* @return {HTMLCanvasElement} [description]
|
||||
*/
|
||||
var create = function (parent, width, height, canvasType)
|
||||
var create = function (parent, width, height, canvasType, selfParent)
|
||||
{
|
||||
if (width === undefined) { width = 1; }
|
||||
if (height === undefined) { height = 1; }
|
||||
if (canvasType === undefined) { canvasType = CONST.CANVAS; }
|
||||
if (selfParent === undefined) { selfParent = false; }
|
||||
|
||||
var canvas;
|
||||
var container = first(canvasType);
|
||||
|
@ -70,6 +72,11 @@ var CanvasPool = function ()
|
|||
canvas = container.canvas;
|
||||
}
|
||||
|
||||
if (selfParent)
|
||||
{
|
||||
container.parent = canvas;
|
||||
}
|
||||
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
|
||||
|
|
|
@ -191,6 +191,24 @@ var BitmapMask = new Class({
|
|||
postRenderCanvas: function ()
|
||||
{
|
||||
// NOOP
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroys this BitmapMask and nulls any references it holds.
|
||||
*
|
||||
* Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it,
|
||||
* so be sure to call `clearMask` on any Game Object using it, before destroying it.
|
||||
*
|
||||
* @method Phaser.Display.Masks.BitmapMask#destroy
|
||||
* @since 3.6.1
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.bitmapMask = null;
|
||||
this.mainTexture = null;
|
||||
this.maskTexture = null;
|
||||
this.mainFramebuffer = null;
|
||||
this.maskFramebuffer = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -131,6 +131,20 @@ var GeometryMask = new Class({
|
|||
postRenderCanvas: function (renderer)
|
||||
{
|
||||
renderer.currentContext.restore();
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroys this GeometryMask and nulls any references it holds.
|
||||
*
|
||||
* Note that if a Game Object is currently using this mask it will _not_ automatically detect you have destroyed it,
|
||||
* so be sure to call `clearMask` on any Game Object using it, before destroying it.
|
||||
*
|
||||
* @method Phaser.Display.Masks.GeometryMask#destroy
|
||||
* @since 3.6.1
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.geometryMask = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -196,7 +196,7 @@ var GetBounds = {
|
|||
* @method Phaser.GameObjects.Components.GetBounds#getBounds
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @generic {Phaser.Math.Vector2} O - [output,$return]
|
||||
* @generic {Phaser.Geom.Rectangle} O - [output,$return]
|
||||
*
|
||||
* @param {(Phaser.Geom.Rectangle|object)} [output] - An object to store the values in. If not provided a new Rectangle will be created.
|
||||
*
|
||||
|
|
|
@ -55,10 +55,19 @@ var Mask = {
|
|||
* @method Phaser.GameObjects.Components.Mask#clearMask
|
||||
* @since 3.6.2
|
||||
*
|
||||
* @param {boolean} [destroyMask=false] - Destroy the mask before clearing it?
|
||||
*
|
||||
* @return {Phaser.GameObjects.GameObject} This Game Object instance.
|
||||
*/
|
||||
clearMask: function ()
|
||||
clearMask: function (destroyMask)
|
||||
{
|
||||
if (destroyMask === undefined) { destroyMask = false; }
|
||||
|
||||
if (destroyMask)
|
||||
{
|
||||
this.mask.destroy();
|
||||
}
|
||||
|
||||
this.mask = null;
|
||||
|
||||
return this;
|
||||
|
|
|
@ -20,7 +20,7 @@ var Texture = {
|
|||
* The Texture this Game Object is using to render with.
|
||||
*
|
||||
* @name Phaser.GameObjects.Components.Texture#texture
|
||||
* @type {Phaser.Textures.Texture}
|
||||
* @type {Phaser.Textures.Texture|Phaser.Textures.CanvasTexture}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
texture: null,
|
||||
|
|
|
@ -1139,7 +1139,7 @@ var Graphics = new Class({
|
|||
|
||||
if (sys.game.renderer.gl && texture)
|
||||
{
|
||||
texture.source[0].glTexture = sys.game.renderer.canvasToTexture(ctx.canvas, texture.source[0].glTexture, true, 0);
|
||||
texture.source[0].glTexture = sys.game.renderer.canvasToTexture(ctx.canvas, texture.source[0].glTexture);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,26 +11,81 @@ var GetFastValue = require('../../utils/object/GetFastValue');
|
|||
var Wrap = require('../../math/Wrap');
|
||||
|
||||
/**
|
||||
* The returned value sets what the property will be at the START of the particles life, on emit.
|
||||
* The returned value sets what the property will be at the START of the particle's life, on emit.
|
||||
* @callback EmitterOpOnEmitCallback
|
||||
*
|
||||
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
|
||||
* @param {string} key - [description]
|
||||
* @param {number} value - [description]
|
||||
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
|
||||
* @param {string} key - The name of the property.
|
||||
* @param {number} value - The current value of the property.
|
||||
*
|
||||
* @return {number} [description]
|
||||
* @return {number} The new value of the property.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The returned value updates the property for the duration of the particles life.
|
||||
* The returned value updates the property for the duration of the particle's life.
|
||||
* @callback EmitterOpOnUpdateCallback
|
||||
*
|
||||
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
|
||||
* @param {string} key - [description]
|
||||
* @param {float} t - The T value (between 0 and 1)
|
||||
* @param {number} value - [description]
|
||||
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
|
||||
* @param {string} key - The name of the property.
|
||||
* @param {float} t - The normalized lifetime of the particle, between 0 (start) and 1 (end).
|
||||
* @param {number} value - The current value of the property.
|
||||
*
|
||||
* @return {number} [description]
|
||||
* @return {number} The new value of the property.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines an operation yielding a random value within a range.
|
||||
* @typedef {object} EmitterOpRandomConfig
|
||||
*
|
||||
* @property {float[]} random - The minimum and maximum values, as [min, max].
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines an operation yielding a random value within a range.
|
||||
* @typedef {object} EmitterOpRandomMinMaxConfig
|
||||
*
|
||||
* @property {float} min - The minimum value.
|
||||
* @property {float} max - The maximum value.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines an operation yielding a random value within a range.
|
||||
* @typedef {object} EmitterOpRandomStartEndConfig
|
||||
*
|
||||
* @property {float} start - The starting value.
|
||||
* @property {float} end - The ending value.
|
||||
* @property {boolean} random - If false, this becomes {@link EmitterOpEaseConfig}.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines an operation yielding a value incremented continuously across a range.
|
||||
* @typedef {object} EmitterOpEaseConfig
|
||||
*
|
||||
* @property {float} start - The starting value.
|
||||
* @property {float} end - The ending value.
|
||||
* @property {string} [ease='Linear'] - The name of the easing function.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines an operation yielding a value incremented by steps across a range.
|
||||
* @typedef {object} EmitterOpSteppedConfig
|
||||
*
|
||||
* @property {number} start - The starting value.
|
||||
* @property {number} end - The ending value.
|
||||
* @property {number} steps - The number of steps between start and end.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} EmitterOpCustomEmitConfig
|
||||
*
|
||||
* @property {EmitterOpOnEmitCallback} onEmit - [description]
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} EmitterOpCustomUpdateConfig
|
||||
*
|
||||
* @property {EmitterOpOnEmitCallback} [onEmit] - [description]
|
||||
* @property {EmitterOpOnUpdateCallback} onUpdate - [description]
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -48,7 +103,10 @@ var Wrap = require('../../math/Wrap');
|
|||
* @param {boolean} [emitOnly=false] - [description]
|
||||
*/
|
||||
var EmitterOp = new Class({
|
||||
initialize: function EmitterOp (config, key, defaultValue, emitOnly)
|
||||
|
||||
initialize:
|
||||
|
||||
function EmitterOp (config, key, defaultValue, emitOnly)
|
||||
{
|
||||
if (emitOnly === undefined)
|
||||
{
|
||||
|
@ -247,7 +305,7 @@ var EmitterOp = new Class({
|
|||
// x: 400
|
||||
|
||||
this.onEmit = this.staticValueEmit;
|
||||
this.onUpdate = this.staticValueUpdate;
|
||||
this.onUpdate = this.staticValueUpdate; // How?
|
||||
}
|
||||
else if (Array.isArray(value))
|
||||
{
|
||||
|
@ -277,18 +335,12 @@ var EmitterOp = new Class({
|
|||
this.onUpdate = value;
|
||||
}
|
||||
}
|
||||
else if (
|
||||
t === 'object' &&
|
||||
(this.has(value, 'random') ||
|
||||
this.hasBoth(value, 'start', 'end') ||
|
||||
this.hasBoth(value, 'min', 'max'))
|
||||
)
|
||||
else if (t === 'object' && (this.has(value, 'random') || this.hasBoth(value, 'start', 'end') || this.hasBoth(value, 'min', 'max')))
|
||||
{
|
||||
this.start = this.has(value, 'start') ? value.start : value.min;
|
||||
this.end = this.has(value, 'end') ? value.end : value.max;
|
||||
|
||||
var isRandom =
|
||||
this.hasBoth(value, 'min', 'max') || this.has(value, 'random');
|
||||
var isRandom = (this.hasBoth(value, 'min', 'max') || this.has(value, 'random'));
|
||||
|
||||
// A random starting value (using 'min | max' instead of 'start | end' automatically implies a random value)
|
||||
|
||||
|
@ -336,13 +388,13 @@ var EmitterOp = new Class({
|
|||
this.onEmit = this.easedValueEmit;
|
||||
}
|
||||
|
||||
// BUG: alpha, rotate, scaleX, scaleY, or tint are eased here if {min, max} is given.
|
||||
// Probably this branch should exclude isRandom entirely.
|
||||
|
||||
this.onUpdate = this.easeValueUpdate;
|
||||
}
|
||||
}
|
||||
else if (
|
||||
t === 'object' &&
|
||||
this.hasEither(value, 'onEmit', 'onUpdate')
|
||||
)
|
||||
else if (t === 'object' && this.hasEither(value, 'onEmit', 'onUpdate'))
|
||||
{
|
||||
// Custom onEmit and onUpdate callbacks
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ var DistanceBetween = require('../../math/distance/DistanceBetween');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* A Particle is a simple Game Object controlled by a Particle Emitter and Manager, and rendered by the Manager.
|
||||
* It uses its own lightweight physics system, and can interact only with its Emitter's bounds and zones.
|
||||
*
|
||||
* @class Particle
|
||||
* @memberOf Phaser.GameObjects.Particles
|
||||
|
@ -37,7 +38,7 @@ var Particle = new Class({
|
|||
this.emitter = emitter;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The texture frame used to render this Particle.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.Particle#frame
|
||||
* @type {Phaser.Textures.Frame}
|
||||
|
@ -47,7 +48,7 @@ var Particle = new Class({
|
|||
this.frame = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The position of this Particle within its Emitter's particle pool.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.Particle#index
|
||||
* @type {number}
|
||||
|
@ -207,7 +208,7 @@ var Particle = new Class({
|
|||
this.tint = 0xffffffff;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The full color of this Particle, computed from its alpha and tint.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.Particle#color
|
||||
* @type {number}
|
||||
|
@ -246,7 +247,7 @@ var Particle = new Class({
|
|||
this.delayCurrent = 0;
|
||||
|
||||
/**
|
||||
* The normalized lifespan T value.
|
||||
* The normalized lifespan T value, where 0 is the start and 1 is the end.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.Particle#lifeT
|
||||
* @type {float}
|
||||
|
@ -405,7 +406,7 @@ var Particle = new Class({
|
|||
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter that is updating this Particle.
|
||||
* @param {number} delta - The delta time in ms.
|
||||
* @param {float} step - The delta value divided by 1000.
|
||||
* @param {array} processors - [description]
|
||||
* @param {array} processors - Particle processors (gravity wells).
|
||||
*/
|
||||
computeVelocity: function (emitter, delta, step, processors)
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -14,7 +14,7 @@ var Render = require('./ParticleManagerRender');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* A Particle Emitter Manager creates and controls {@link Phaser.GameObjects.Particles.ParticleEmitter Particle Emitters} and {@link Phaser.GameObjects.Particles.GravityWell Gravity Wells}.
|
||||
*
|
||||
* @class ParticleEmitterManager
|
||||
* @extends Phaser.GameObjects.GameObject
|
||||
|
@ -26,10 +26,10 @@ var Render = require('./ParticleManagerRender');
|
|||
* @extends Phaser.GameObjects.Particles.Components.Visible
|
||||
* @extends Phaser.GameObjects.Particles.Components.Pipeline
|
||||
*
|
||||
* @param {Phaser.Scene} scene - [description]
|
||||
* @param {string} texture - [description]
|
||||
* @param {(string|integer)} frame - [description]
|
||||
* @param {Phaser.GameObjects.Particles.ParticleEmitter[]} emitters - [description]
|
||||
* @param {Phaser.Scene} scene - The Scene to which this Emitter Manager belongs.
|
||||
* @param {string} texture - The key of the Texture this Emitter Manager will use to render particles, as stored in the Texture Manager.
|
||||
* @param {(string|integer)} frame - An optional frame from the Texture this Emitter Manager will use to render particles.
|
||||
* @param {ParticleEmitterConfig|ParticleEmitterConfig[]} emitters - Configuration settings for one or more emitters to create.
|
||||
*/
|
||||
var ParticleEmitterManager = new Class({
|
||||
|
||||
|
@ -53,7 +53,7 @@ var ParticleEmitterManager = new Class({
|
|||
* [description]
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#blendMode
|
||||
* @type {number}
|
||||
* @type {integer}
|
||||
* @default -1
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
|
@ -61,7 +61,9 @@ var ParticleEmitterManager = new Class({
|
|||
this.blendMode = -1;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The time scale applied to all emitters and particles, affecting flow rate, lifespan, and movement.
|
||||
* Values larger than 1 are faster than normal.
|
||||
* This is multiplied with any timeScale set on each individual emitter.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#timeScale
|
||||
* @type {float}
|
||||
|
@ -71,7 +73,7 @@ var ParticleEmitterManager = new Class({
|
|||
this.timeScale = 1;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The texture used to render this Emitter Manager's particles.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#texture
|
||||
* @type {Phaser.Textures.Texture}
|
||||
|
@ -81,7 +83,7 @@ var ParticleEmitterManager = new Class({
|
|||
this.texture = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The texture frame used to render this Emitter Manager's particles.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#frame
|
||||
* @type {Phaser.Textures.Frame}
|
||||
|
@ -91,7 +93,7 @@ var ParticleEmitterManager = new Class({
|
|||
this.frame = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Names of this Emitter Manager's texture frames.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#frameNames
|
||||
* @type {Phaser.Textures.Frame[]}
|
||||
|
@ -144,7 +146,7 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Sets the texture and frame this Game Object will use to render with.
|
||||
* Sets the texture and frame this Emitter Manager will use to render with.
|
||||
*
|
||||
* Textures are referenced by their string-based keys, as stored in the Texture Manager.
|
||||
*
|
||||
|
@ -154,7 +156,7 @@ var ParticleEmitterManager = new Class({
|
|||
* @param {string} key - The key of the texture to be used, as stored in the Texture Manager.
|
||||
* @param {(string|integer)} [frame] - The name or index of the frame within the Texture.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Game Object.
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Emitter Manager.
|
||||
*/
|
||||
setTexture: function (key, frame)
|
||||
{
|
||||
|
@ -164,7 +166,7 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Sets the frame this Game Object will use to render with.
|
||||
* Sets the frame this Emitter Manager will use to render with.
|
||||
*
|
||||
* The Frame has to belong to the current Texture being used.
|
||||
*
|
||||
|
@ -175,7 +177,7 @@ var ParticleEmitterManager = new Class({
|
|||
*
|
||||
* @param {(string|integer)} [frame] - The name or index of the frame within the Texture.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Game Object.
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Emitter Manager.
|
||||
*/
|
||||
setFrame: function (frame)
|
||||
{
|
||||
|
@ -189,15 +191,15 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Assigns texture frames to an emitter.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#setEmitterFrames
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {(Phaser.Textures.Frame|Phaser.Textures.Frame[])} frames - [description]
|
||||
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - [description]
|
||||
* @param {(Phaser.Textures.Frame|Phaser.Textures.Frame[])} frames - The texture frames.
|
||||
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The particle emitter to modify.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Game Object.
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Emitter Manager.
|
||||
*/
|
||||
setEmitterFrames: function (frames, emitter)
|
||||
{
|
||||
|
@ -233,7 +235,7 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Adds an existing Particle Emitter to this Manager.
|
||||
* Adds an existing Particle Emitter to this Emitter Manager.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#addEmitter
|
||||
* @since 3.0.0
|
||||
|
@ -248,7 +250,7 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Creates a new Particle Emitter object, adds it to this Manager and returns a reference to it.
|
||||
* Creates a new Particle Emitter object, adds it to this Emitter Manager and returns a reference to it.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#createEmitter
|
||||
* @since 3.0.0
|
||||
|
@ -263,7 +265,7 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Adds an existing Gravity Well object to this Manager.
|
||||
* Adds an existing Gravity Well object to this Emitter Manager.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#addGravityWell
|
||||
* @since 3.0.0
|
||||
|
@ -278,7 +280,7 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Creates a new Gravity Well, adds it to this Manager and returns a reference to it.
|
||||
* Creates a new Gravity Well, adds it to this Emitter Manager and returns a reference to it.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#createGravityWell
|
||||
* @since 3.0.0
|
||||
|
@ -293,16 +295,16 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Emits particles from each active emitter.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#emitParticle
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} count - [description]
|
||||
* @param {number} x - [description]
|
||||
* @param {number} y - [description]
|
||||
* @param {integer} [count] - The number of particles to release from each emitter. The default is the emitter's own {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}.
|
||||
* @param {float} [x] - The x-coordinate to to emit particles from. The default is the x-coordinate of the emitter's current location.
|
||||
* @param {float} [y] - The y-coordinate to to emit particles from. The default is the y-coordinate of the emitter's current location.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Game Object.
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Emitter Manager.
|
||||
*/
|
||||
emitParticle: function (count, x, y)
|
||||
{
|
||||
|
@ -322,16 +324,16 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Emits particles from each active emitter.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#emitParticleAt
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} x - [description]
|
||||
* @param {number} y - [description]
|
||||
* @param {integer} count - [description]
|
||||
* @param {float} [x] - The x-coordinate to to emit particles from. The default is the x-coordinate of the emitter's current location.
|
||||
* @param {float} [y] - The y-coordinate to to emit particles from. The default is the y-coordinate of the emitter's current location.
|
||||
* @param {integer} [count] - The number of particles to release from each emitter. The default is the emitter's own {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}.
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Game Object.
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Emitter Manager.
|
||||
*/
|
||||
emitParticleAt: function (x, y, count)
|
||||
{
|
||||
|
@ -348,7 +350,7 @@ var ParticleEmitterManager = new Class({
|
|||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#pause
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Game Object.
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Emitter Manager.
|
||||
*/
|
||||
pause: function ()
|
||||
{
|
||||
|
@ -363,7 +365,7 @@ var ParticleEmitterManager = new Class({
|
|||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#resume
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Game Object.
|
||||
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} This Emitter Manager.
|
||||
*/
|
||||
resume: function ()
|
||||
{
|
||||
|
@ -373,12 +375,12 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Gets all active particle processors (gravity wells).
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#getProcessors
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.GameObjects.Particles.GravityWell[]} [description]
|
||||
* @return {Phaser.GameObjects.Particles.GravityWell[]} - The active gravity wells.
|
||||
*/
|
||||
getProcessors: function ()
|
||||
{
|
||||
|
@ -386,13 +388,13 @@ var ParticleEmitterManager = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Updates all active emitters.
|
||||
*
|
||||
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#preUpdate
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
|
||||
* @param {number} delta - The delta time, in ms, elapsed since the last frame.
|
||||
* @param {float} delta - The delta time, in ms, elapsed since the last frame.
|
||||
*/
|
||||
preUpdate: function (time, delta)
|
||||
{
|
||||
|
|
|
@ -6,6 +6,27 @@
|
|||
|
||||
var Class = require('../../../utils/Class');
|
||||
|
||||
/**
|
||||
* @callback DeathZoneSourceCallback
|
||||
*
|
||||
* @param {float} x - [description]
|
||||
* @param {float} y - [description]
|
||||
*
|
||||
* @return {boolean} - True if the coordinates are within the source area.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} DeathZoneSource
|
||||
*
|
||||
* @property {DeathZoneSourceCallback} contains
|
||||
*
|
||||
* @see Phaser.Geom.Circle
|
||||
* @see Phaser.Geom.Ellipse
|
||||
* @see Phaser.Geom.Polygon
|
||||
* @see Phaser.Geom.Rectangle
|
||||
* @see Phaser.Geom.Triangle
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A Death Zone.
|
||||
|
@ -20,7 +41,7 @@ var Class = require('../../../utils/Class');
|
|||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {object} source - An object instance that has a `contains` method that returns a boolean when given `x` and `y` arguments.
|
||||
* @param {DeathZoneSource} source - An object instance that has a `contains` method that returns a boolean when given `x` and `y` arguments.
|
||||
* @param {boolean} killOnEnter - Should the Particle be killed when it enters the zone? `true` or leaves it? `false`
|
||||
*/
|
||||
var DeathZone = new Class({
|
||||
|
@ -34,7 +55,7 @@ var DeathZone = new Class({
|
|||
* This could be a Geometry shape, such as `Phaser.Geom.Circle`, or your own custom object.
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.Zones.DeathZone#source
|
||||
* @type {object}
|
||||
* @type {DeathZoneSource}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.source = source;
|
||||
|
|
|
@ -6,16 +6,40 @@
|
|||
|
||||
var Class = require('../../../utils/Class');
|
||||
|
||||
/**
|
||||
* @callback EdgeZoneSourceCallback
|
||||
*
|
||||
* @param {integer} quantity - [description]
|
||||
* @param {integer} [stepRate] - [description]
|
||||
*
|
||||
* @return {Phaser.Geom.Point[]} - [description]
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} EdgeZoneSource
|
||||
*
|
||||
* @property {EdgeZoneSourceCallback} getPoints - A function placing points on the source's edge or edges.
|
||||
*
|
||||
* @see Phaser.Curves.Curve
|
||||
* @see Phaser.Curves.Path
|
||||
* @see Phaser.Geom.Circle
|
||||
* @see Phaser.Geom.Ellipse
|
||||
* @see Phaser.Geom.Line
|
||||
* @see Phaser.Geom.Polygon
|
||||
* @see Phaser.Geom.Rectangle
|
||||
* @see Phaser.Geom.Triangle
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* A zone that places particles on a shape's edges.
|
||||
*
|
||||
* @class EdgeZone
|
||||
* @memberOf Phaser.GameObjects.Particles.Zones
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {object} source - [description]
|
||||
* @param {EdgeZoneSource} source - An object instance with a `getPoints(quantity, stepRate)` method returning an array of points.
|
||||
* @param {number} quantity - [description]
|
||||
* @param {number} stepRate - [description]
|
||||
* @param {boolean} [yoyo=false] - [description]
|
||||
|
@ -34,7 +58,7 @@ var EdgeZone = new Class({
|
|||
* [description]
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.Zones.EdgeZone#source
|
||||
* @type {object}
|
||||
* @type {EdgeZoneSource|RandomZoneSource}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.source = source;
|
||||
|
|
|
@ -7,16 +7,35 @@
|
|||
var Class = require('../../../utils/Class');
|
||||
var Vector2 = require('../../../math/Vector2');
|
||||
|
||||
/**
|
||||
* @callback RandomZoneSourceCallback
|
||||
*
|
||||
* @param {Phaser.Math.Vector2} point - A point to modify.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} RandomZoneSource
|
||||
*
|
||||
* @property {RandomZoneSourceCallback} getRandomPoint - A function modifying its point argument.
|
||||
*
|
||||
* @see Phaser.Geom.Circle
|
||||
* @see Phaser.Geom.Ellipse
|
||||
* @see Phaser.Geom.Line
|
||||
* @see Phaser.Geom.Polygon
|
||||
* @see Phaser.Geom.Rectangle
|
||||
* @see Phaser.Geom.Triangle
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* A zone that places particles randomly within a shape's area.
|
||||
*
|
||||
* @class RandomZone
|
||||
* @memberOf Phaser.GameObjects.Particles.Zones
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {object} source - [description]
|
||||
* @param {RandomZoneSource} source - An object instance with a `getRandomPoint(point)` method.
|
||||
*/
|
||||
var RandomZone = new Class({
|
||||
|
||||
|
@ -28,7 +47,7 @@ var RandomZone = new Class({
|
|||
* [description]
|
||||
*
|
||||
* @name Phaser.GameObjects.Particles.Zones.RandomZone#source
|
||||
* @type {object}
|
||||
* @type {RandomZoneSource}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.source = source;
|
||||
|
|
|
@ -30,7 +30,7 @@ var TextWebGLRenderer = function (renderer, src, interpolationPercentage, camera
|
|||
|
||||
if (src.dirty)
|
||||
{
|
||||
src.canvasTexture = renderer.canvasToTexture(src.canvas, src.canvasTexture, true, src.scaleMode);
|
||||
src.canvasTexture = renderer.canvasToTexture(src.canvas, src.canvasTexture);
|
||||
src.dirty = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -248,7 +248,7 @@ var TileSprite = new Class({
|
|||
this.potWidth, this.potHeight
|
||||
);
|
||||
|
||||
this.tileTexture = this.renderer.canvasToTexture(this.canvasBuffer, this.tileTexture, (this.tileTexture === null), this.scaleMode);
|
||||
this.tileTexture = this.renderer.canvasToTexture(this.canvasBuffer, this.tileTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -40,14 +40,33 @@ var XHRSettings = require('./XHRSettings');
|
|||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Loader.LoaderPlugin} loader - The Loader that is going to load this File.
|
||||
* @param {FileConfig} fileConfig - [description]
|
||||
*/
|
||||
var File = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function File (fileConfig)
|
||||
function File (loader, fileConfig)
|
||||
{
|
||||
/**
|
||||
* A reference to the Loader that is going to load this file.
|
||||
*
|
||||
* @name Phaser.Loader.File#loader
|
||||
* @type {Phaser.Loader.LoaderPlugin}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.loader = loader;
|
||||
|
||||
/**
|
||||
* A reference to the Cache, or Texture Manager, that is going to store this file if it loads.
|
||||
*
|
||||
* @name Phaser.Loader.File#cache
|
||||
* @type {(Phaser.Cache.BaseCache|Phaser.Textures.TextureManager)}
|
||||
* @since 3.7.0
|
||||
*/
|
||||
this.cache = GetFastValue(fileConfig, 'cache', false);
|
||||
|
||||
/**
|
||||
* The file type string (image, json, etc) for sorting within the Loader.
|
||||
*
|
||||
|
@ -112,15 +131,6 @@ var File = new Class({
|
|||
this.xhrSettings = MergeXHRSettings(this.xhrSettings, GetFastValue(fileConfig, 'xhrSettings', {}));
|
||||
}
|
||||
|
||||
/**
|
||||
* The LoaderPlugin instance that is loading this file.
|
||||
*
|
||||
* @name Phaser.Loader.File#loader
|
||||
* @type {?Phaser.Loader.LoaderPlugin}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.loader = null;
|
||||
|
||||
/**
|
||||
* The XMLHttpRequest instance (as created by XHR Loader) that is loading this File.
|
||||
*
|
||||
|
@ -275,22 +285,18 @@ var File = new Class({
|
|||
*
|
||||
* @method Phaser.Loader.File#load
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Loader.LoaderPlugin} loader - The Loader that will load this File.
|
||||
*/
|
||||
load: function (loader)
|
||||
load: function ()
|
||||
{
|
||||
this.loader = loader;
|
||||
|
||||
if (this.state === CONST.FILE_POPULATED)
|
||||
{
|
||||
this.onComplete();
|
||||
|
||||
loader.nextFile(this);
|
||||
this.loader.nextFile(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.src = GetURL(this, loader.baseURL);
|
||||
this.src = GetURL(this, this.loader.baseURL);
|
||||
|
||||
if (this.src.indexOf('data:') === 0)
|
||||
{
|
||||
|
@ -298,7 +304,7 @@ var File = new Class({
|
|||
}
|
||||
else
|
||||
{
|
||||
this.xhrLoader = XHRLoader(this, loader.xhr);
|
||||
this.xhrLoader = XHRLoader(this, this.loader.xhr);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -407,6 +413,39 @@ var File = new Class({
|
|||
{
|
||||
this.state = CONST.FILE_COMPLETE;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if a key matching the one used by this file exists in the target Cache or not.
|
||||
* This is called automatically by the LoaderPlugin to decide if the file can be safely
|
||||
* loaded or will conflict.
|
||||
*
|
||||
* @method Phaser.Loader.File#hasCacheConflict
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @return {boolean} `true` if adding this file will cause a conflict, otherwise `false`.
|
||||
*/
|
||||
hasCacheConflict: function ()
|
||||
{
|
||||
return (this.cache && this.cache.exists(this.key));
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds this file to its target cache upon successful loading and processing.
|
||||
* It will emit a `filecomplete` event from the LoaderPlugin.
|
||||
* This method is often overridden by specific file types.
|
||||
*
|
||||
* @method Phaser.Loader.File#addToCache
|
||||
* @since 3.7.0
|
||||
*/
|
||||
addToCache: function ()
|
||||
{
|
||||
if (this.cache)
|
||||
{
|
||||
this.cache.add(this.key, this.data);
|
||||
}
|
||||
|
||||
this.loader.emit('filecomplete', this.key, this);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -84,6 +84,24 @@ var LoaderPlugin = new Class({
|
|||
*/
|
||||
this.systems = scene.sys;
|
||||
|
||||
/**
|
||||
* A reference to the global Cache Manager.
|
||||
*
|
||||
* @name Phaser.Loader.LoaderPlugin#cacheManager
|
||||
* @type {Phaser.Cache.CacheManager}
|
||||
* @since 3.7.0
|
||||
*/
|
||||
this.cacheManager = scene.sys.cache;
|
||||
|
||||
/**
|
||||
* A reference to the global Texture Manager.
|
||||
*
|
||||
* @name Phaser.Loader.LoaderPlugin#textureManager
|
||||
* @type {Phaser.Textures.TextureManager}
|
||||
* @since 3.7.0
|
||||
*/
|
||||
this.textureManager = scene.sys.textures;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
|
@ -350,9 +368,13 @@ var LoaderPlugin = new Class({
|
|||
return -1;
|
||||
}
|
||||
|
||||
file.path = this.path;
|
||||
// Does the file already exist in the cache or texture manager?
|
||||
if (!file.hasCacheConflict())
|
||||
{
|
||||
file.path = this.path;
|
||||
|
||||
this.list.set(file);
|
||||
this.list.set(file);
|
||||
}
|
||||
|
||||
return file;
|
||||
},
|
||||
|
@ -721,12 +743,6 @@ var LoaderPlugin = new Class({
|
|||
animJSON.push(file);
|
||||
break;
|
||||
|
||||
case 'image':
|
||||
case 'svg':
|
||||
case 'html':
|
||||
textures.addImage(file.key, file.data);
|
||||
break;
|
||||
|
||||
case 'atlasjson':
|
||||
|
||||
fileA = file.fileA;
|
||||
|
@ -789,34 +805,6 @@ var LoaderPlugin = new Class({
|
|||
}
|
||||
break;
|
||||
|
||||
case 'spritesheet':
|
||||
textures.addSpriteSheet(file.key, file.data, file.config);
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
cache.json.add(file.key, file.data);
|
||||
break;
|
||||
|
||||
case 'xml':
|
||||
cache.xml.add(file.key, file.data);
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
cache.text.add(file.key, file.data);
|
||||
break;
|
||||
|
||||
case 'obj':
|
||||
cache.obj.add(file.key, file.data);
|
||||
break;
|
||||
|
||||
case 'binary':
|
||||
cache.binary.add(file.key, file.data);
|
||||
break;
|
||||
|
||||
case 'audio':
|
||||
cache.audio.add(file.key, file.data);
|
||||
break;
|
||||
|
||||
case 'audioSprite':
|
||||
|
||||
var files = [ file.fileA, file.fileB ];
|
||||
|
@ -828,14 +816,9 @@ var LoaderPlugin = new Class({
|
|||
|
||||
break;
|
||||
|
||||
case 'glsl':
|
||||
cache.shader.add(file.key, file.data);
|
||||
break;
|
||||
default:
|
||||
file.addToCache();
|
||||
|
||||
case 'tilemapCSV':
|
||||
case 'tilemapJSON':
|
||||
cache.tilemap.add(file.key, { format: file.tilemapFormat, data: file.data });
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1027,6 +1010,8 @@ var LoaderPlugin = new Class({
|
|||
|
||||
this.scene = null;
|
||||
this.systems = null;
|
||||
this.textureManager = null;
|
||||
this.cacheManager = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -20,9 +20,9 @@ var JSONFile = require('./JSONFile.js');
|
|||
*
|
||||
* @return {Phaser.Loader.FileTypes.JSONFile} A File instance to be added to the Loader.
|
||||
*/
|
||||
var AnimationJSONFile = function (key, url, path, xhrSettings)
|
||||
var AnimationJSONFile = function (loader, key, url, xhrSettings)
|
||||
{
|
||||
var json = new JSONFile(key, url, path, xhrSettings);
|
||||
var json = new JSONFile(loader, key, url, xhrSettings);
|
||||
|
||||
// Override the File type
|
||||
json.type = 'animationJSON';
|
||||
|
@ -55,12 +55,12 @@ FileTypesManager.register('animation', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new AnimationJSONFile(key[i], url, this.path, xhrSettings));
|
||||
this.addFile(new AnimationJSONFile(this, key[i], url, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new AnimationJSONFile(key, url, this.path, xhrSettings));
|
||||
this.addFile(new AnimationJSONFile(this, key, url, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -23,10 +23,10 @@ var JSONFile = require('./JSONFile.js');
|
|||
*
|
||||
* @return {object} An object containing two File objects to be added to the loader.
|
||||
*/
|
||||
var AtlasJSONFile = function (key, textureURL, atlasURL, path, textureXhrSettings, atlasXhrSettings)
|
||||
var AtlasJSONFile = function (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
|
||||
{
|
||||
var image = new ImageFile(key, textureURL, path, textureXhrSettings);
|
||||
var data = new JSONFile(key, atlasURL, path, atlasXhrSettings);
|
||||
var image = new ImageFile(loader, key, textureURL, textureXhrSettings);
|
||||
var data = new JSONFile(loader, key, atlasURL, atlasXhrSettings);
|
||||
|
||||
// Link them together
|
||||
image.linkFile = data;
|
||||
|
@ -60,20 +60,19 @@ var AtlasJSONFile = function (key, textureURL, atlasURL, path, textureXhrSetting
|
|||
*/
|
||||
FileTypesManager.register('atlas', function (key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
|
||||
{
|
||||
|
||||
var files;
|
||||
|
||||
// If param key is an object, use object based loading method
|
||||
if ((typeof key === 'object') && (key !== null))
|
||||
{
|
||||
files = new AtlasJSONFile(key.key, key.texture, key.data, this.path, textureXhrSettings, atlasXhrSettings);
|
||||
files = new AtlasJSONFile(this, key.key, key.texture, key.data, textureXhrSettings, atlasXhrSettings);
|
||||
}
|
||||
|
||||
// Else just use the parameters like normal
|
||||
else
|
||||
{
|
||||
// Returns an object with two properties: 'texture' and 'data'
|
||||
files = new AtlasJSONFile(key, textureURL, atlasURL, this.path, textureXhrSettings, atlasXhrSettings);
|
||||
files = new AtlasJSONFile(this, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings);
|
||||
}
|
||||
|
||||
this.addFile(files.texture);
|
||||
|
|
|
@ -33,7 +33,7 @@ var AudioFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function AudioFile (key, url, path, xhrSettings, audioContext)
|
||||
function AudioFile (loader, key, url, xhrSettings, audioContext)
|
||||
{
|
||||
/**
|
||||
* [description]
|
||||
|
@ -46,15 +46,16 @@ var AudioFile = new Class({
|
|||
|
||||
var fileConfig = {
|
||||
type: 'audio',
|
||||
cache: loader.cacheManager.audio,
|
||||
extension: GetFastValue(url, 'type', ''),
|
||||
responseType: 'arraybuffer',
|
||||
key: key,
|
||||
url: GetFastValue(url, 'uri', url),
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: xhrSettings
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -119,11 +120,11 @@ AudioFile.create = function (loader, key, urls, config, xhrSettings)
|
|||
|
||||
if (deviceAudio.webAudio && !(audioConfig && audioConfig.disableWebAudio))
|
||||
{
|
||||
return new AudioFile(key, url, loader.path, xhrSettings, game.sound.context);
|
||||
return new AudioFile(loader, key, url, xhrSettings, game.sound.context);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new HTML5AudioFile(key, url, loader.path, config);
|
||||
return new HTML5AudioFile(loader, key, url, config);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ FileTypesManager.register('audioSprite', function (key, urls, json, config, audi
|
|||
|
||||
if (typeof json === 'string')
|
||||
{
|
||||
jsonFile = new JSONFile(key, json, this.path, jsonXhrSettings);
|
||||
jsonFile = new JSONFile(this, key, json, jsonXhrSettings);
|
||||
|
||||
this.addFile(jsonFile);
|
||||
}
|
||||
|
|
|
@ -31,21 +31,22 @@ var BinaryFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function BinaryFile (key, url, path, xhrSettings)
|
||||
function BinaryFile (loader, key, url, xhrSettings)
|
||||
{
|
||||
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
|
||||
|
||||
var fileConfig = {
|
||||
type: 'binary',
|
||||
cache: loader.cacheManager.binary,
|
||||
extension: GetFastValue(key, 'extension', 'bin'),
|
||||
responseType: 'arraybuffer',
|
||||
key: fileKey,
|
||||
url: GetFastValue(key, 'file', url),
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
|
@ -85,12 +86,12 @@ FileTypesManager.register('binary', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new BinaryFile(key[i], url, this.path, xhrSettings));
|
||||
this.addFile(new BinaryFile(this, key[i], url, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new BinaryFile(key, url, this.path, xhrSettings));
|
||||
this.addFile(new BinaryFile(this, key, url, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -23,10 +23,10 @@ var XMLFile = require('./XMLFile.js');
|
|||
*
|
||||
* @return {object} An object containing two File objects to be added to the loader.
|
||||
*/
|
||||
var BitmapFontFile = function (key, textureURL, xmlURL, path, textureXhrSettings, xmlXhrSettings)
|
||||
var BitmapFontFile = function (loader, key, textureURL, xmlURL, textureXhrSettings, xmlXhrSettings)
|
||||
{
|
||||
var image = new ImageFile(key, textureURL, path, textureXhrSettings);
|
||||
var data = new XMLFile(key, xmlURL, path, xmlXhrSettings);
|
||||
var image = new ImageFile(loader, key, textureURL, textureXhrSettings);
|
||||
var data = new XMLFile(loader, key, xmlURL, xmlXhrSettings);
|
||||
|
||||
// Link them together
|
||||
image.linkFile = data;
|
||||
|
@ -61,7 +61,7 @@ var BitmapFontFile = function (key, textureURL, xmlURL, path, textureXhrSettings
|
|||
FileTypesManager.register('bitmapFont', function (key, textureURL, xmlURL, textureXhrSettings, xmlXhrSettings)
|
||||
{
|
||||
// Returns an object with two properties: 'texture' and 'data'
|
||||
var files = new BitmapFontFile(key, textureURL, xmlURL, this.path, textureXhrSettings, xmlXhrSettings);
|
||||
var files = new BitmapFontFile(this, key, textureURL, xmlURL, textureXhrSettings, xmlXhrSettings);
|
||||
|
||||
this.addFile(files.texture);
|
||||
this.addFile(files.data);
|
||||
|
|
|
@ -31,21 +31,22 @@ var GLSLFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function GLSLFile (key, url, path, xhrSettings)
|
||||
function GLSLFile (loader, key, url, xhrSettings)
|
||||
{
|
||||
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
|
||||
|
||||
var fileConfig = {
|
||||
type: 'glsl',
|
||||
cache: loader.cacheManager.shader,
|
||||
extension: GetFastValue(key, 'extension', 'glsl'),
|
||||
responseType: 'text',
|
||||
key: fileKey,
|
||||
url: GetFastValue(key, 'file', url),
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
|
@ -85,12 +86,12 @@ FileTypesManager.register('glsl', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new GLSLFile(key[i], url, this.path, xhrSettings));
|
||||
this.addFile(new GLSLFile(this, key[i], url, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new GLSLFile(key, url, this.path, xhrSettings));
|
||||
this.addFile(new GLSLFile(this, key, url, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -30,23 +30,24 @@ var HTML5AudioFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function HTML5AudioFile (key, url, path, config)
|
||||
{
|
||||
this.locked = 'ontouchstart' in window;
|
||||
function HTML5AudioFile (loader, key, url, config)
|
||||
{
|
||||
this.locked = 'ontouchstart' in window;
|
||||
|
||||
this.loaded = false;
|
||||
this.loaded = false;
|
||||
|
||||
var fileConfig = {
|
||||
type: 'audio',
|
||||
extension: GetFastValue(url, 'type', ''),
|
||||
key: key,
|
||||
url: GetFastValue(url, 'uri', url),
|
||||
path: path,
|
||||
config: config
|
||||
};
|
||||
var fileConfig = {
|
||||
type: 'audio',
|
||||
cache: loader.cacheManager.audio,
|
||||
extension: GetFastValue(url, 'type', ''),
|
||||
key: key,
|
||||
url: GetFastValue(url, 'uri', url),
|
||||
path: loader.path,
|
||||
config: config
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
},
|
||||
File.call(this, loader, fileConfig);
|
||||
},
|
||||
|
||||
onLoad: function ()
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ var HTMLFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function HTMLFile (key, url, width, height, path, xhrSettings)
|
||||
function HTMLFile (loader, key, url, width, height, xhrSettings)
|
||||
{
|
||||
if (width === undefined) { width = 512; }
|
||||
if (height === undefined) { height = 512; }
|
||||
|
@ -42,11 +42,12 @@ var HTMLFile = new Class({
|
|||
|
||||
var fileConfig = {
|
||||
type: 'html',
|
||||
cache: loader.textureManager,
|
||||
extension: GetFastValue(key, 'extension', 'html'),
|
||||
responseType: 'text',
|
||||
key: fileKey,
|
||||
url: GetFastValue(key, 'file', url),
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: GetFastValue(key, 'xhr', xhrSettings),
|
||||
config: {
|
||||
width: width,
|
||||
|
@ -54,7 +55,7 @@ var HTMLFile = new Class({
|
|||
}
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
|
@ -113,6 +114,13 @@ var HTMLFile = new Class({
|
|||
};
|
||||
|
||||
File.createObjectURL(this.data, blob, 'image/svg+xml');
|
||||
},
|
||||
|
||||
addToCache: function ()
|
||||
{
|
||||
this.cache.addImage(this.key, this.data);
|
||||
|
||||
this.loader.emit('filecomplete', this.key, this);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -143,12 +151,12 @@ FileTypesManager.register('html', function (key, url, width, height, xhrSettings
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new HTMLFile(key[i], url, width, height, this.path, xhrSettings));
|
||||
this.addFile(new HTMLFile(this, key[i], url, width, height, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new HTMLFile(key, url, width, height, this.path, xhrSettings));
|
||||
this.addFile(new HTMLFile(this, key, url, width, height, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -61,23 +61,24 @@ var ImageFile = new Class({
|
|||
// this.load.image({ key: 'bunny' });
|
||||
// this.load.image({ key: 'bunny', extension: 'jpg' });
|
||||
|
||||
function ImageFile (key, url, path, xhrSettings, config)
|
||||
function ImageFile (loader, key, url, xhrSettings, config)
|
||||
{
|
||||
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
|
||||
var fileUrl = (url === undefined) ? GetFastValue(key, 'file') : url;
|
||||
|
||||
var fileConfig = {
|
||||
type: 'image',
|
||||
cache: loader.textureManager,
|
||||
extension: GetFastValue(key, 'extension', 'png'),
|
||||
responseType: 'blob',
|
||||
key: fileKey,
|
||||
url: fileUrl,
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: GetFastValue(key, 'xhr', xhrSettings),
|
||||
config: GetFastValue(key, 'config', config)
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
|
@ -109,6 +110,13 @@ var ImageFile = new Class({
|
|||
};
|
||||
|
||||
File.createObjectURL(this.data, this.xhrLoader.response, 'image/png');
|
||||
},
|
||||
|
||||
addToCache: function ()
|
||||
{
|
||||
this.cache.addImage(this.key, this.data);
|
||||
|
||||
this.loader.emit('filecomplete', this.key, this);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -145,14 +153,14 @@ FileTypesManager.register('image', function (key, url, xhrSettings)
|
|||
|
||||
if (Array.isArray(urls) && urls.length === 2)
|
||||
{
|
||||
fileA = this.addFile(new ImageFile(key[i], urls[0], this.path, xhrSettings));
|
||||
fileB = this.addFile(new ImageFile(key[i], urls[1], this.path, xhrSettings));
|
||||
fileA = this.addFile(new ImageFile(this, key[i], urls[0], xhrSettings));
|
||||
fileB = this.addFile(new ImageFile(this, key[i], urls[1], xhrSettings));
|
||||
|
||||
fileA.setLinkFile(fileB, 'dataimage');
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new ImageFile(key[i], url, this.path, xhrSettings));
|
||||
this.addFile(new ImageFile(this, key[i], url, xhrSettings));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,14 +170,14 @@ FileTypesManager.register('image', function (key, url, xhrSettings)
|
|||
|
||||
if (Array.isArray(urls) && urls.length === 2)
|
||||
{
|
||||
fileA = this.addFile(new ImageFile(key, urls[0], this.path, xhrSettings));
|
||||
fileB = this.addFile(new ImageFile(key, urls[1], this.path, xhrSettings));
|
||||
fileA = this.addFile(new ImageFile(this, key, urls[0], xhrSettings));
|
||||
fileB = this.addFile(new ImageFile(this, key, urls[1], xhrSettings));
|
||||
|
||||
fileA.setLinkFile(fileB, 'dataimage');
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new ImageFile(key, url, this.path, xhrSettings));
|
||||
this.addFile(new ImageFile(this, key, url, xhrSettings));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,21 +33,22 @@ var JSONFile = new Class({
|
|||
|
||||
// url can either be a string, in which case it is treated like a proper url, or an object, in which case it is treated as a ready-made JS Object
|
||||
|
||||
function JSONFile (key, url, path, xhrSettings)
|
||||
function JSONFile (loader, key, url, xhrSettings)
|
||||
{
|
||||
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
|
||||
|
||||
var fileConfig = {
|
||||
type: 'json',
|
||||
cache: loader.cacheManager.json,
|
||||
extension: GetFastValue(key, 'extension', 'json'),
|
||||
responseType: 'text',
|
||||
key: fileKey,
|
||||
url: GetFastValue(key, 'file', url),
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
|
||||
if (typeof fileConfig.url === 'object')
|
||||
{
|
||||
|
|
|
@ -61,7 +61,7 @@ FileTypesManager.register('multiatlas', function (key, textureURLs, atlasURLs, t
|
|||
{
|
||||
multiKey = '_MA_IMG_' + key + '_' + i.toString();
|
||||
|
||||
file = new ImageFile(multiKey, textureURLs[i], this.path, textureXhrSettings);
|
||||
file = new ImageFile(this, multiKey, textureURLs[i], textureXhrSettings);
|
||||
|
||||
this.addFile(file);
|
||||
|
||||
|
@ -72,7 +72,7 @@ FileTypesManager.register('multiatlas', function (key, textureURLs, atlasURLs, t
|
|||
{
|
||||
multiKey = '_MA_JSON_' + key + '_' + i.toString();
|
||||
|
||||
file = new JSONFile(multiKey, atlasURLs[i], this.path, atlasXhrSettings);
|
||||
file = new JSONFile(this, multiKey, atlasURLs[i], atlasXhrSettings);
|
||||
|
||||
this.addFile(file);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ var PluginFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function PluginFile (key, url, path, xhrSettings)
|
||||
function PluginFile (loader, key, url, xhrSettings)
|
||||
{
|
||||
// If the url variable refers to a class, add the plugin directly
|
||||
if (typeof url === 'function')
|
||||
|
@ -46,11 +46,12 @@ var PluginFile = new Class({
|
|||
|
||||
var fileConfig = {
|
||||
type: 'script',
|
||||
cache: false,
|
||||
extension: GetFastValue(key, 'extension', 'js'),
|
||||
responseType: 'text',
|
||||
key: fileKey,
|
||||
url: GetFastValue(key, 'file', url),
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
|
||||
};
|
||||
|
||||
|
@ -103,12 +104,12 @@ FileTypesManager.register('plugin', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new PluginFile(key[i], url, this.path, xhrSettings));
|
||||
this.addFile(new PluginFile(this, key[i], url, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new PluginFile(key, url, this.path, xhrSettings));
|
||||
this.addFile(new PluginFile(this, key, url, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -31,21 +31,22 @@ var SVGFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function SVGFile (key, url, path, xhrSettings)
|
||||
function SVGFile (loader, key, url, xhrSettings)
|
||||
{
|
||||
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
|
||||
|
||||
var fileConfig = {
|
||||
type: 'svg',
|
||||
cache: loader.textureManager,
|
||||
extension: GetFastValue(key, 'extension', 'svg'),
|
||||
responseType: 'text',
|
||||
key: fileKey,
|
||||
url: GetFastValue(key, 'file', url),
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
|
@ -106,6 +107,13 @@ var SVGFile = new Class({
|
|||
};
|
||||
|
||||
File.createObjectURL(this.data, blob, 'image/svg+xml');
|
||||
},
|
||||
|
||||
addToCache: function ()
|
||||
{
|
||||
this.cache.addImage(this.key, this.data);
|
||||
|
||||
this.loader.emit('filecomplete', this.key, this);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -134,12 +142,12 @@ FileTypesManager.register('svg', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new SVGFile(key[i], url, this.path, xhrSettings));
|
||||
this.addFile(new SVGFile(this, key[i], url, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new SVGFile(key, url, this.path, xhrSettings));
|
||||
this.addFile(new SVGFile(this, key, url, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -31,17 +31,18 @@ var ScriptFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function ScriptFile (key, url, path, xhrSettings)
|
||||
function ScriptFile (loader, key, url, xhrSettings)
|
||||
{
|
||||
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
|
||||
|
||||
var fileConfig = {
|
||||
type: 'script',
|
||||
cache: false,
|
||||
extension: GetFastValue(key, 'extension', 'js'),
|
||||
responseType: 'text',
|
||||
key: fileKey,
|
||||
url: GetFastValue(key, 'file', url),
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
|
||||
};
|
||||
|
||||
|
@ -91,12 +92,12 @@ FileTypesManager.register('script', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new ScriptFile(key[i], url, this.path, xhrSettings));
|
||||
this.addFile(new ScriptFile(this, key[i], url, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new ScriptFile(key, url, this.path, xhrSettings));
|
||||
this.addFile(new ScriptFile(this, key, url, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -21,13 +21,20 @@ var ImageFile = require('./ImageFile.js');
|
|||
*
|
||||
* @return {object} An object containing two File objects to be added to the loader.
|
||||
*/
|
||||
var SpriteSheetFile = function (key, url, config, path, xhrSettings)
|
||||
var SpriteSheetFile = function (loader, key, url, config, xhrSettings)
|
||||
{
|
||||
var image = new ImageFile(key, url, path, xhrSettings, config);
|
||||
var image = new ImageFile(loader, key, url, xhrSettings, config);
|
||||
|
||||
// Override the File type
|
||||
image.type = 'spritesheet';
|
||||
|
||||
image.addToCache = function ()
|
||||
{
|
||||
this.cache.addSpriteSheet(this.key, this.data, this.config);
|
||||
|
||||
this.loader.emit('filecomplete', this.key, this);
|
||||
};
|
||||
|
||||
return image;
|
||||
};
|
||||
|
||||
|
@ -56,12 +63,12 @@ FileTypesManager.register('spritesheet', function (key, url, config, xhrSettings
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new SpriteSheetFile(key[i], url, null, this.path, xhrSettings));
|
||||
this.addFile(new SpriteSheetFile(this, key[i], url, null, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new SpriteSheetFile(key, url, config, this.path, xhrSettings));
|
||||
this.addFile(new SpriteSheetFile(this, key, url, config, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -30,19 +30,20 @@ var TextFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function TextFile (key, url, path, xhrSettings)
|
||||
function TextFile (loader, key, url, xhrSettings)
|
||||
{
|
||||
var fileConfig = {
|
||||
type: 'text',
|
||||
cache: loader.cacheManager.text,
|
||||
extension: 'txt',
|
||||
responseType: 'text',
|
||||
key: key,
|
||||
url: url,
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: xhrSettings
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
|
@ -82,12 +83,12 @@ FileTypesManager.register('text', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new TextFile(key[i], url, this.path, xhrSettings));
|
||||
this.addFile(new TextFile(this, key[i], url, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new TextFile(key, url, this.path, xhrSettings));
|
||||
this.addFile(new TextFile(this, key, url, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -32,19 +32,20 @@ var TilemapCSVFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function TilemapCSVFile (key, url, path, format, xhrSettings)
|
||||
function TilemapCSVFile (loader, key, url, format, xhrSettings)
|
||||
{
|
||||
var fileConfig = {
|
||||
type: 'tilemapCSV',
|
||||
cache: loader.cacheManager.tilemap,
|
||||
extension: '.csv',
|
||||
responseType: 'text',
|
||||
key: key,
|
||||
url: url,
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: xhrSettings
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
|
||||
this.tilemapFormat = format;
|
||||
},
|
||||
|
@ -58,6 +59,13 @@ var TilemapCSVFile = new Class({
|
|||
this.onComplete();
|
||||
|
||||
callback(this);
|
||||
},
|
||||
|
||||
addToCache: function ()
|
||||
{
|
||||
this.cache.add(this.key, { format: this.tilemapFormat, data: this.data });
|
||||
|
||||
this.loader.emit('filecomplete', this.key, this);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -86,12 +94,12 @@ FileTypesManager.register('tilemapCSV', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new TilemapCSVFile(key[i], url, this.path, TILEMAP_FORMATS.CSV, xhrSettings));
|
||||
this.addFile(new TilemapCSVFile(this, key[i], url, TILEMAP_FORMATS.CSV, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new TilemapCSVFile(key, url, this.path, TILEMAP_FORMATS.CSV, xhrSettings));
|
||||
this.addFile(new TilemapCSVFile(this, key, url, TILEMAP_FORMATS.CSV, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -22,15 +22,24 @@ var TILEMAP_FORMATS = require('../../tilemaps/Formats');
|
|||
*
|
||||
* @return {object} An object containing two File objects to be added to the loader.
|
||||
*/
|
||||
var TilemapJSONFile = function (key, url, path, format, xhrSettings)
|
||||
var TilemapJSONFile = function (loader, key, url, format, xhrSettings)
|
||||
{
|
||||
var json = new JSONFile(key, url, path, xhrSettings);
|
||||
var json = new JSONFile(loader, key, url, xhrSettings);
|
||||
|
||||
// Override the File type
|
||||
json.type = 'tilemapJSON';
|
||||
|
||||
json.cache = loader.cacheManager.tilemap;
|
||||
|
||||
json.tilemapFormat = format;
|
||||
|
||||
json.addToCache = function ()
|
||||
{
|
||||
this.cache.add(this.key, { format: this.tilemapFormat, data: this.data });
|
||||
|
||||
this.loader.emit('filecomplete', this.key, this);
|
||||
};
|
||||
|
||||
return json;
|
||||
};
|
||||
|
||||
|
@ -58,12 +67,12 @@ FileTypesManager.register('tilemapTiledJSON', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(TilemapJSONFile(key[i], url, this.path, TILEMAP_FORMATS.TILED_JSON, xhrSettings));
|
||||
this.addFile(TilemapJSONFile(this, key[i], url, TILEMAP_FORMATS.TILED_JSON, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(TilemapJSONFile(key, url, this.path, TILEMAP_FORMATS.TILED_JSON, xhrSettings));
|
||||
this.addFile(TilemapJSONFile(this, key, url, TILEMAP_FORMATS.TILED_JSON, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
@ -94,12 +103,12 @@ FileTypesManager.register('tilemapWeltmeister', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(TilemapJSONFile(key[i], url, this.path, TILEMAP_FORMATS.WELTMEISTER, xhrSettings));
|
||||
this.addFile(TilemapJSONFile(this, key[i], url, TILEMAP_FORMATS.WELTMEISTER, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(TilemapJSONFile(key, url, this.path, TILEMAP_FORMATS.WELTMEISTER, xhrSettings));
|
||||
this.addFile(TilemapJSONFile(this, key, url, TILEMAP_FORMATS.WELTMEISTER, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -23,10 +23,10 @@ var TextFile = require('./TextFile.js');
|
|||
*
|
||||
* @return {object} An object containing two File objects to be added to the loader.
|
||||
*/
|
||||
var UnityAtlasFile = function (key, textureURL, atlasURL, path, textureXhrSettings, atlasXhrSettings)
|
||||
var UnityAtlasFile = function (loader, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
|
||||
{
|
||||
var image = new ImageFile(key, textureURL, path, textureXhrSettings);
|
||||
var data = new TextFile(key, atlasURL, path, atlasXhrSettings);
|
||||
var image = new ImageFile(loader, key, textureURL, textureXhrSettings);
|
||||
var data = new TextFile(loader, key, atlasURL, atlasXhrSettings);
|
||||
|
||||
// Link them together
|
||||
image.linkFile = data;
|
||||
|
@ -61,7 +61,7 @@ var UnityAtlasFile = function (key, textureURL, atlasURL, path, textureXhrSettin
|
|||
FileTypesManager.register('unityAtlas', function (key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings)
|
||||
{
|
||||
// Returns an object with two properties: 'texture' and 'data'
|
||||
var files = new UnityAtlasFile(key, textureURL, atlasURL, this.path, textureXhrSettings, atlasXhrSettings);
|
||||
var files = new UnityAtlasFile(this, key, textureURL, atlasURL, textureXhrSettings, atlasXhrSettings);
|
||||
|
||||
this.addFile(files.texture);
|
||||
this.addFile(files.data);
|
||||
|
|
|
@ -32,21 +32,22 @@ var XMLFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
function XMLFile (key, url, path, xhrSettings)
|
||||
function XMLFile (loader, key, url, xhrSettings)
|
||||
{
|
||||
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
|
||||
|
||||
var fileConfig = {
|
||||
type: 'xml',
|
||||
cache: loader.cacheManager.xml,
|
||||
extension: GetFastValue(key, 'extension', 'xml'),
|
||||
responseType: 'text',
|
||||
key: fileKey,
|
||||
url: GetFastValue(key, 'file', url),
|
||||
path: path,
|
||||
path: loader.path,
|
||||
xhrSettings: GetFastValue(key, 'xhr', xhrSettings)
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
File.call(this, loader, fileConfig);
|
||||
},
|
||||
|
||||
onProcess: function (callback)
|
||||
|
@ -91,12 +92,12 @@ FileTypesManager.register('xml', function (key, url, xhrSettings)
|
|||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
|
||||
this.addFile(new XMLFile(key[i], url, this.path, xhrSettings));
|
||||
this.addFile(new XMLFile(this, key[i], url, xhrSettings));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addFile(new XMLFile(key, url, this.path, xhrSettings));
|
||||
this.addFile(new XMLFile(this, key, url, xhrSettings));
|
||||
}
|
||||
|
||||
// For method chaining
|
||||
|
|
|
@ -5,15 +5,15 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Calculates the positive difference of two given numbers.
|
||||
*
|
||||
* @function Phaser.Math.Difference
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} a - [description]
|
||||
* @param {number} b - [description]
|
||||
* @param {number} a - The first number in the calculation.
|
||||
* @param {number} b - The second number in the calculation.
|
||||
*
|
||||
* @return {number} [description]
|
||||
* @return {number} The positive difference of the two given numbers.
|
||||
*/
|
||||
var Difference = function (a, b)
|
||||
{
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Calculates the factorial of a given number for integer values greater than 0.
|
||||
*
|
||||
* @function Phaser.Math.Factorial
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} value - [description]
|
||||
* @param {number} value - A positive integer to calculate the factorial of.
|
||||
*
|
||||
* @return {number} [description]
|
||||
* @return {number} The factorial of the given number.
|
||||
*/
|
||||
var Factorial = function (value)
|
||||
{
|
||||
|
|
|
@ -5,15 +5,15 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Generate a random floating point number between the two given bounds, minimum inclusive, maximum exclusive.
|
||||
*
|
||||
* @function Phaser.Math.FloatBetween
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {float} min - [description]
|
||||
* @param {float} max - [description]
|
||||
* @param {float} min - The lower bound for the float, inclusive.
|
||||
* @param {float} max - The upper bound for the float exclusive.
|
||||
*
|
||||
* @return {float} [description]
|
||||
* @return {float} A random float within the given range.
|
||||
*/
|
||||
var FloatBetween = function (min, max)
|
||||
{
|
||||
|
|
|
@ -12,15 +12,15 @@
|
|||
module.exports = {
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Packs four floats on a range from 0.0 to 1.0 into a single Uint32
|
||||
*
|
||||
* @function Phaser.Renderer.WebGL.Utils.getTintFromFloats
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} r - [description]
|
||||
* @param {number} r - Red component in a range from 0.0 to 1.0
|
||||
* @param {number} g - [description]
|
||||
* @param {number} b - [description]
|
||||
* @param {number} a - [description]
|
||||
* @param {number} a - Alpha component in a range from 0.0 to 1.0
|
||||
*
|
||||
* @return {number} [description]
|
||||
*/
|
||||
|
@ -35,15 +35,16 @@ module.exports = {
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Packs a Uint24, representing RGB components, with a Float32, representing
|
||||
* the alpha component, with a range between 0.0 and 1.0 and return a Uint32
|
||||
*
|
||||
* @function Phaser.Renderer.WebGL.Utils.getTintAppendFloatAlpha
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} rgb - [description]
|
||||
* @param {number} a - [description]
|
||||
* @param {number} rgb - Uint24 representing RGB components
|
||||
* @param {number} a - Float32 representing Alpha component
|
||||
*
|
||||
* @return {number} [description]
|
||||
* @return {number} Packed RGBA as Uint32
|
||||
*/
|
||||
getTintAppendFloatAlpha: function (rgb, a)
|
||||
{
|
||||
|
@ -52,15 +53,17 @@ module.exports = {
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Packs a Uint24, representing RGB components, with a Float32, representing
|
||||
* the alpha component, with a range between 0.0 and 1.0 and return a
|
||||
* swizzled Uint32
|
||||
*
|
||||
* @function Phaser.Renderer.WebGL.Utils.getTintAppendFloatAlphaAndSwap
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} rgb - [description]
|
||||
* @param {number} a - [description]
|
||||
* @param {number} rgb - Uint24 representing RGB components
|
||||
* @param {number} a - Float32 representing Alpha component
|
||||
*
|
||||
* @return {number} [description]
|
||||
* @return {number} Packed RGBA as Uint32
|
||||
*/
|
||||
getTintAppendFloatAlphaAndSwap: function (rgb, a)
|
||||
{
|
||||
|
@ -73,14 +76,14 @@ module.exports = {
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Unpacks a Uint24 RGB into an array of floats of ranges of 0.0 and 1.0
|
||||
*
|
||||
* @function Phaser.Renderer.WebGL.Utils.getFloatsFromUintRGB
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} rgb - [description]
|
||||
* @param {number} rgb - RGB packed as a Uint24
|
||||
*
|
||||
* @return {number} [description]
|
||||
* @return {array} Array of floats representing each component as a float
|
||||
*/
|
||||
getFloatsFromUintRGB: function (rgb)
|
||||
{
|
||||
|
@ -92,15 +95,15 @@ module.exports = {
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Counts how many attributes of 32 bits a vertex has
|
||||
*
|
||||
* @function Phaser.Renderer.WebGL.Utils.getComponentCount
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} attributes - [description]
|
||||
* @param {WebGLRenderingContext} glContext - [description]
|
||||
* @param {array} attributes - Array of attributes
|
||||
* @param {WebGLRenderingContext} glContext - WebGLContext used for check types
|
||||
*
|
||||
* @return {number} [description]
|
||||
* @return {number} Count of 32 bit attributes in vertex
|
||||
*/
|
||||
getComponentCount: function (attributes, glContext)
|
||||
{
|
||||
|
|
|
@ -10,7 +10,35 @@ var Utils = require('./Utils');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* WebGLPipeline is a class that describes the way elements will be rendererd
|
||||
* in WebGL, specially focused on batching vertices (batching is not provided).
|
||||
* Pipelines are mostly used for describing 2D rendering passes but it's
|
||||
* flexible enough to be used for any type of rendering including 3D.
|
||||
* Internally WebGLPipeline will handle things like compiling shaders,
|
||||
* creating vertex buffers, assigning primitive topology and binding
|
||||
* vertex attributes.
|
||||
*
|
||||
* The config properties are:
|
||||
* - game: Current game instance.
|
||||
* - renderer: Current WebGL renderer.
|
||||
* - gl: Current WebGL context.
|
||||
* - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES.
|
||||
* Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants).
|
||||
* - vertShader: Source for vertex shader as a string.
|
||||
* - fragShader: Source for fragment shader as a string.
|
||||
* - vertexCapacity: The amount of vertices that shall be allocated
|
||||
* - vertexSize: The size of a single vertex in bytes.
|
||||
* - vertices: An optional buffer of vertices
|
||||
* - attributes: An array describing the vertex attributes
|
||||
*
|
||||
* The vertex attributes properties are:
|
||||
* - name : String - Name of the attribute in the vertex shader
|
||||
* - size : integer - How many components describe the attribute. For ex: vec3 = size of 3, float = size of 1
|
||||
* - type : GLenum - WebGL type (gl.BYTE, gl.SHORT, gl.UNSIGNED_BYTE, gl.UNSIGNED_SHORT, gl.FLOAT)
|
||||
* - normalized : boolean - Is the attribute normalized
|
||||
* - offset : integer - The offset in bytes to the current attribute in the vertex. Equivalent to offsetof(vertex, attrib) in C
|
||||
* Here you can find more information of how to describe an attribute:
|
||||
* - https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer
|
||||
*
|
||||
* @class WebGLPipeline
|
||||
* @memberOf Phaser.Renderer.WebGL
|
||||
|
@ -26,7 +54,7 @@ var WebGLPipeline = new Class({
|
|||
function WebGLPipeline (config)
|
||||
{
|
||||
/**
|
||||
* [description]
|
||||
* Name of the Pipeline. Used for identifying
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#name
|
||||
* @type {string}
|
||||
|
@ -53,7 +81,7 @@ var WebGLPipeline = new Class({
|
|||
this.view = config.game.canvas;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Used to store the current game resolution
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#resolution
|
||||
* @type {number}
|
||||
|
@ -62,7 +90,7 @@ var WebGLPipeline = new Class({
|
|||
this.resolution = config.game.config.resolution;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Width of the current viewport
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#width
|
||||
* @type {number}
|
||||
|
@ -71,7 +99,7 @@ var WebGLPipeline = new Class({
|
|||
this.width = config.game.config.width * this.resolution;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Height of the current viewport
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#height
|
||||
* @type {number}
|
||||
|
@ -89,7 +117,7 @@ var WebGLPipeline = new Class({
|
|||
this.gl = config.gl;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* How many vertices have been fed to the current pipeline.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexCount
|
||||
* @type {number}
|
||||
|
@ -99,7 +127,7 @@ var WebGLPipeline = new Class({
|
|||
this.vertexCount = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The limit of vertices that the pipeline can hold
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexCapacity
|
||||
* @type {integer}
|
||||
|
@ -117,7 +145,7 @@ var WebGLPipeline = new Class({
|
|||
this.renderer = config.renderer;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Raw byte buffer of vertices.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexData
|
||||
* @type {ArrayBuffer}
|
||||
|
@ -126,7 +154,7 @@ var WebGLPipeline = new Class({
|
|||
this.vertexData = (config.vertices ? config.vertices : new ArrayBuffer(config.vertexCapacity * config.vertexSize));
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The handle to a WebGL vertex buffer object.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexBuffer
|
||||
* @type {WebGLBuffer}
|
||||
|
@ -135,7 +163,7 @@ var WebGLPipeline = new Class({
|
|||
this.vertexBuffer = this.renderer.createVertexBuffer((config.vertices ? config.vertices : this.vertexData.byteLength), this.gl.STREAM_DRAW);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The handle to a WebGL program
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#program
|
||||
* @type {WebGLProgram}
|
||||
|
@ -144,7 +172,7 @@ var WebGLPipeline = new Class({
|
|||
this.program = this.renderer.createProgram(config.vertShader, config.fragShader);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Array of objects that describe the vertex attributes
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#attributes
|
||||
* @type {object}
|
||||
|
@ -153,7 +181,7 @@ var WebGLPipeline = new Class({
|
|||
this.attributes = config.attributes;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The size in bytes of the vertex
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#vertexSize
|
||||
* @type {integer}
|
||||
|
@ -162,7 +190,7 @@ var WebGLPipeline = new Class({
|
|||
this.vertexSize = config.vertexSize;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The primitive topology which the pipeline will use to submit draw calls
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#topology
|
||||
* @type {integer}
|
||||
|
@ -171,7 +199,8 @@ var WebGLPipeline = new Class({
|
|||
this.topology = config.topology;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Uint8 view to the vertex raw buffer. Used for uploading vertex buffer resources
|
||||
* to the GPU.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLPipeline#bytes
|
||||
* @type {Uint8Array}
|
||||
|
@ -200,16 +229,16 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Adds a description of vertex attribute to the pipeline
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#addAttribute
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param {string} name - [description]
|
||||
* @param {integer} size - [description]
|
||||
* @param {integer} type - [description]
|
||||
* @param {boolean} normalized - [description]
|
||||
* @param {integer} offset - [description]
|
||||
* @param {string} name - Name of the vertex attribute
|
||||
* @param {integer} size - Vertex component size
|
||||
* @param {integer} type - Type of the attribute
|
||||
* @param {boolean} normalized - Is the value normalized to a range
|
||||
* @param {integer} offset - Byte offset to the beginning of the first element in the vertex
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
|
||||
*/
|
||||
|
@ -227,7 +256,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Check if the current batch of vertices is full.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#shouldFlush
|
||||
* @since 3.0.0
|
||||
|
@ -240,7 +269,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Resizes the properties used to describe the viewport
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#resize
|
||||
* @since 3.0.0
|
||||
|
@ -259,7 +288,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Binds the pipeline resources, including programs, vertex buffers and binds attributes
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#bind
|
||||
* @since 3.0.0
|
||||
|
@ -357,7 +386,8 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Uploads the vertex data and emits a draw call
|
||||
* for the current batch of vertices.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#flush
|
||||
* @since 3.0.0
|
||||
|
@ -413,7 +443,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Set a uniform value of the current pipeline program.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat1
|
||||
* @since 3.2.0
|
||||
|
@ -430,7 +460,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Set a uniform value of the current pipeline program.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat2
|
||||
* @since 3.2.0
|
||||
|
@ -449,7 +479,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Set a uniform value of the current pipeline program.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat3
|
||||
* @since 3.2.0
|
||||
|
@ -469,16 +499,16 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Set a uniform value of the current pipeline program.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat4
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param {string} name - [description]
|
||||
* @param {float} x - [description]
|
||||
* @param {float} y - [description]
|
||||
* @param {float} z - [description]
|
||||
* @param {float} w - [description]
|
||||
* @param {string} name - Name of the uniform
|
||||
* @param {float} x - X component of the uniform
|
||||
* @param {float} y - Y component of the uniform
|
||||
* @param {float} z - Z component of the uniform
|
||||
* @param {float} w - W component of the uniform
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
|
||||
*/
|
||||
|
@ -490,7 +520,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Set a uniform value of the current pipeline program.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setInt1
|
||||
* @since 3.2.0
|
||||
|
@ -507,7 +537,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Set a uniform value of the current pipeline program.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setInt2
|
||||
* @since 3.2.0
|
||||
|
@ -525,7 +555,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Set a uniform value of the current pipeline program.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setInt3
|
||||
* @since 3.2.0
|
||||
|
@ -544,16 +574,16 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Set a uniform value of the current pipeline program.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setInt4
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param {string} name - [description]
|
||||
* @param {integer} x - [description]
|
||||
* @param {integer} y - [description]
|
||||
* @param {integer} z - [description]
|
||||
* @param {integer} w - [description]
|
||||
* @param {string} name - Name of the uniform
|
||||
* @param {integer} x - X component of the uniform
|
||||
* @param {integer} y - Y component of the uniform
|
||||
* @param {integer} z - Z component of the uniform
|
||||
* @param {integer} w - W component of the uniform
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
|
||||
*/
|
||||
|
@ -564,6 +594,7 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Set a uniform value of the current pipeline program.
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setMatrix2
|
||||
|
@ -582,6 +613,8 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Set a uniform value of the current pipeline program.
|
||||
* [description]
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setMatrix3
|
||||
|
@ -600,14 +633,14 @@ var WebGLPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Set a uniform value of the current pipeline program.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLPipeline#setMatrix4
|
||||
* @since 3.2.0
|
||||
*
|
||||
* @param {string} name - [description]
|
||||
* @param {boolean} transpose - [description]
|
||||
* @param {Float32Array} matrix - [description]
|
||||
* @param {string} name - Name of the uniform
|
||||
* @param {boolean} transpose - Should the matrix be transpose
|
||||
* @param {Float32Array} matrix - Matrix data
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
|
||||
*/
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../../const');
|
||||
var IsSizePowerOfTwo = require('../../math/pow2/IsSizePowerOfTwo');
|
||||
var SpliceOne = require('../../utils/array/SpliceOne');
|
||||
var Utils = require('./Utils');
|
||||
var WebGLSnapshot = require('../snapshot/WebGLSnapshot');
|
||||
|
||||
|
@ -33,7 +34,13 @@ var TextureTintPipeline = require('./pipelines/TextureTintPipeline');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* WebGLRenderer is a class that contains the needed functionality to keep the
|
||||
* WebGLRenderingContext state clean. The main idea of the WebGLRenderer is to keep track of
|
||||
* any context change that happens for WebGL rendering inside of Phaser. This means
|
||||
* if raw webgl functions are called outside the WebGLRenderer of the Phaser WebGL
|
||||
* rendering ecosystem they might pollute the current WebGLRenderingContext state producing
|
||||
* unexpected behaviour. It's recommended that WebGL interaction is done through
|
||||
* WebGLRenderer and/or WebGLPipeline.
|
||||
*
|
||||
* @class WebGLRenderer
|
||||
* @memberOf Phaser.Renderer.WebGL
|
||||
|
@ -155,7 +162,7 @@ var WebGLRenderer = new Class({
|
|||
this.blendModes = [];
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Keeps track of any WebGLTexture created with the current WebGLRenderingContext
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#nativeTextures
|
||||
* @type {array}
|
||||
|
@ -175,7 +182,7 @@ var WebGLRenderer = new Class({
|
|||
this.contextLost = false;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* This object will store all pipelines created through addPipeline
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#pipelines
|
||||
* @type {object}
|
||||
|
@ -200,7 +207,7 @@ var WebGLRenderer = new Class({
|
|||
// Internal Renderer State (Textures, Framebuffers, Pipelines, Buffers, etc)
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Cached value for the last texture unit that was used
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentActiveTextureUnit
|
||||
* @type {integer}
|
||||
|
@ -209,7 +216,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentActiveTextureUnit = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* An array of the last texture handles that were bound to the WebGLRenderingContext
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentTextures
|
||||
* @type {array}
|
||||
|
@ -218,7 +225,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentTextures = new Array(16);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Current framebuffer in use
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentFramebuffer
|
||||
* @type {WebGLFramebuffer}
|
||||
|
@ -228,7 +235,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentFramebuffer = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Current WebGLPipeline in use
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentPipeline
|
||||
* @type {Phaser.Renderer.WebGL.WebGLPipeline}
|
||||
|
@ -238,7 +245,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentPipeline = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Current WebGLProgram in use
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentProgram
|
||||
* @type {WebGLProgram}
|
||||
|
@ -248,7 +255,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentProgram = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Current WebGLBuffer (Vertex buffer) in use
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentVertexBuffer
|
||||
* @type {WebGLBuffer}
|
||||
|
@ -258,7 +265,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentVertexBuffer = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Current WebGLBuffer (Index buffer) in use
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentIndexBuffer
|
||||
* @type {WebGLBuffer}
|
||||
|
@ -268,7 +275,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentIndexBuffer = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Current blend mode in use
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentBlendMode
|
||||
* @type {integer}
|
||||
|
@ -277,7 +284,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentBlendMode = Infinity;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Indicates if the the scissor state is enabled in WebGLRenderingContext
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentScissorEnabled
|
||||
* @type {boolean}
|
||||
|
@ -287,7 +294,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentScissorEnabled = false;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Stores the current scissor data
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentScissor
|
||||
* @type {Uint32Array}
|
||||
|
@ -296,7 +303,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentScissor = new Uint32Array([ 0, 0, this.width, this.height ]);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Index to the scissor stack top
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentScissorIdx
|
||||
* @type {number}
|
||||
|
@ -306,7 +313,7 @@ var WebGLRenderer = new Class({
|
|||
this.currentScissorIdx = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Stack of scissor data
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#scissorStack
|
||||
* @type {Uint32Array}
|
||||
|
@ -339,7 +346,7 @@ var WebGLRenderer = new Class({
|
|||
}
|
||||
}, false);
|
||||
|
||||
// This are initialized post context creation
|
||||
// These are initialized post context creation
|
||||
|
||||
/**
|
||||
* [description]
|
||||
|
@ -352,7 +359,7 @@ var WebGLRenderer = new Class({
|
|||
this.gl = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Array of strings that indicate which WebGL extensions are supported by the browser
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#supportedExtensions
|
||||
* @type {object}
|
||||
|
@ -362,7 +369,7 @@ var WebGLRenderer = new Class({
|
|||
this.supportedExtensions = null;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Extensions loaded into the current context
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#extensions
|
||||
* @type {object}
|
||||
|
@ -372,7 +379,7 @@ var WebGLRenderer = new Class({
|
|||
this.extensions = {};
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Stores the current WebGL component formats for further use
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.WebGLRenderer#glFormats
|
||||
* @type {array}
|
||||
|
@ -385,7 +392,8 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Creates a new WebGLRenderingContext and initializes all internal
|
||||
* state.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#init
|
||||
* @since 3.0.0
|
||||
|
@ -532,12 +540,12 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Checks if a WebGL extension is supported
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#hasExtension
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string} extensionName - [description]
|
||||
* @param {string} extensionName - Name of the WebGL extension
|
||||
*
|
||||
* @return {boolean} [description]
|
||||
*/
|
||||
|
@ -547,14 +555,14 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Loads a WebGL extension
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#getExtension
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string} extensionName - [description]
|
||||
*
|
||||
* @return {object} [description]
|
||||
* @return {object} WebGL extension if the extension is supported
|
||||
*/
|
||||
getExtension: function (extensionName)
|
||||
{
|
||||
|
@ -569,7 +577,7 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Flushes the current pipeline if the pipeline is bound
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#flush
|
||||
* @since 3.0.0
|
||||
|
@ -585,12 +593,12 @@ var WebGLRenderer = new Class({
|
|||
/* Renderer State Manipulation Functions */
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Checks if a pipeline is present in the current WebGLRenderer
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#hasPipeline
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string} pipelineName - [description]
|
||||
* @param {string} pipelineName - Name of the pipeline
|
||||
*
|
||||
* @return {boolean} [description]
|
||||
*/
|
||||
|
@ -600,7 +608,7 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Returns the pipeline by name if the pipeline exists
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#getPipeline
|
||||
* @since 3.0.0
|
||||
|
@ -615,7 +623,7 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Removes a pipeline by name
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#removePipeline
|
||||
* @since 3.0.0
|
||||
|
@ -632,15 +640,15 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Adds a pipeline instance into the collection of pipelines
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#addPipeline
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string} pipelineName - [description]
|
||||
* @param {Phaser.Renderer.WebGL.WebGLPipeline} pipelineInstance - [description]
|
||||
* @param {Phaser.Renderer.WebGL.WebGLPipeline} pipelineInstance - Pipeline instance must extend WebGLPipeline
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
|
||||
* @return {Phaser.Renderer.WebGL.WebGLPipeline} The instance that was passed.
|
||||
*/
|
||||
addPipeline: function (pipelineName, pipelineInstance)
|
||||
{
|
||||
|
@ -661,7 +669,7 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Sets the current scissor state
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setScissor
|
||||
* @since 3.0.0
|
||||
|
@ -708,7 +716,7 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Pushes a new scissor state. This is used to set nested scissor states.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#pushScissor
|
||||
* @since 3.0.0
|
||||
|
@ -738,7 +746,7 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Pops the last scissor state and sets it.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#popScissor
|
||||
* @since 3.0.0
|
||||
|
@ -762,7 +770,7 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Binds a WebGLPipeline and sets it as the current pipeline to be used.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setPipeline
|
||||
* @since 3.0.0
|
||||
|
@ -891,13 +899,14 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Binds a texture at a texture unit. If a texture is already
|
||||
* bound to that unit it will force a flush on the current pipeline.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setTexture2D
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {WebGLTexture} texture - [description]
|
||||
* @param {integer} textureUnit - [description]
|
||||
* @param {WebGLTexture} texture - The WebGL texture that needs to be bound
|
||||
* @param {integer} textureUnit - The texture unit to which the texture will be bound
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
||||
*/
|
||||
|
@ -925,12 +934,13 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Binds a framebuffer. If there was another framebuffer already bound
|
||||
* it will force a pipeline flush.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setFramebuffer
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {WebGLFramebuffer} framebuffer - [description]
|
||||
* @param {WebGLFramebuffer} framebuffer - The framebuffer that needs to be bound
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
||||
*/
|
||||
|
@ -951,12 +961,13 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Binds a program. If there was another program already bound
|
||||
* it will force a pipeline flush
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setProgram
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {WebGLProgram} program - [description]
|
||||
* @param {WebGLProgram} program - The program that needs to be bound
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
||||
*/
|
||||
|
@ -977,12 +988,13 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Bounds a vertex buffer. If there is a vertex buffer already bound
|
||||
* it'll force a pipeline flush.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setVertexBuffer
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {WebGLBuffer} vertexBuffer - [description]
|
||||
* @param {WebGLBuffer} vertexBuffer - The buffer that needs to be bound
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
||||
*/
|
||||
|
@ -1003,12 +1015,13 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Bounds a index buffer. If there is a index buffer already bound
|
||||
* it'll force a pipeline flush.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setIndexBuffer
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {WebGLBuffer} indexBuffer - [description]
|
||||
* @param {WebGLBuffer} indexBuffer - The buffer the needs to be bound
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLRenderer} This WebGL Renderer.
|
||||
*/
|
||||
|
@ -1031,7 +1044,8 @@ var WebGLRenderer = new Class({
|
|||
/* Renderer Resource Creation Functions */
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Creates a texture from an image source. If the source is not valid
|
||||
* it creates an empty texture
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#createTextureFromSource
|
||||
* @since 3.0.0
|
||||
|
@ -1080,23 +1094,24 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* A wrapper for creating a WebGLTexture. If not pixel data is passed
|
||||
* it will create an empty texture.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#createTexture2D
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} mipLevel - [description]
|
||||
* @param {integer} minFilter - [description]
|
||||
* @param {integer} magFilter - [description]
|
||||
* @param {integer} wrapT - [description]
|
||||
* @param {integer} wrapS - [description]
|
||||
* @param {integer} format - [description]
|
||||
* @param {object} pixels - [description]
|
||||
* @param {integer} width - [description]
|
||||
* @param {integer} height - [description]
|
||||
* @param {boolean} pma - [description]
|
||||
* @param {integer} mipLevel - Mip level of the texture
|
||||
* @param {integer} minFilter - Filtering of the texture
|
||||
* @param {integer} magFilter - Filtering of the texture
|
||||
* @param {integer} wrapT - Wrapping mode of the texture
|
||||
* @param {integer} wrapS - Wrapping mode of the texture
|
||||
* @param {integer} format - Which format does the texture use
|
||||
* @param {object} pixels - pixel data
|
||||
* @param {integer} width - Width of the texture in pixels
|
||||
* @param {integer} height - Height of the texture in pixels
|
||||
* @param {boolean} pma - Does the texture hace premultiplied alpha.
|
||||
*
|
||||
* @return {WebGLTexture} [description]
|
||||
* @return {WebGLTexture} Raw WebGLTexture
|
||||
*/
|
||||
createTexture2D: function (mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, pma)
|
||||
{
|
||||
|
@ -1137,17 +1152,17 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Wrapper for creating WebGLFramebuffer.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#createFramebuffer
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} width - [description]
|
||||
* @param {integer} height - [description]
|
||||
* @param {WebGLFramebuffer} renderTexture - [description]
|
||||
* @param {boolean} addDepthStencilBuffer - [description]
|
||||
* @param {integer} width - Width in pixels of the framebuffer
|
||||
* @param {integer} height - Height in pixels of the framebuffer
|
||||
* @param {WebGLTexture} renderTexture - The color texture to where the color pixels are written
|
||||
* @param {boolean} addDepthStencilBuffer - Indicates if the current framebuffer support depth and stencil buffers
|
||||
*
|
||||
* @return {WebGLFramebuffer} [description]
|
||||
* @return {WebGLFramebuffer} Raw WebGLFramebuffer
|
||||
*/
|
||||
createFramebuffer: function (width, height, renderTexture, addDepthStencilBuffer)
|
||||
{
|
||||
|
@ -1192,15 +1207,15 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Wrapper for creating a WebGLProgram
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#createProgram
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string} vertexShader - [description]
|
||||
* @param {string} fragmentShader - [description]
|
||||
* @param {string} vertexShader - Source to the vertex shader
|
||||
* @param {string} fragmentShader - Source to the fragment shader
|
||||
*
|
||||
* @return {WebGLProgram} [description]
|
||||
* @return {WebGLProgram} Raw WebGLProgram
|
||||
*/
|
||||
createProgram: function (vertexShader, fragmentShader)
|
||||
{
|
||||
|
@ -1236,15 +1251,15 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Wrapper for creating a vertex buffer.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#createVertexBuffer
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {ArrayBuffer} initialDataOrSize - [description]
|
||||
* @param {integer} bufferUsage - [description]
|
||||
* @param {ArrayBuffer} initialDataOrSize - It's either ArrayBuffer or an integer indicating the size of the vbo
|
||||
* @param {integer} bufferUsage - How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW
|
||||
*
|
||||
* @return {WebGLBuffer} [description]
|
||||
* @return {WebGLBuffer} Raw vertex buffer
|
||||
*/
|
||||
createVertexBuffer: function (initialDataOrSize, bufferUsage)
|
||||
{
|
||||
|
@ -1261,15 +1276,15 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Wrapper for creating a vertex buffer.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#createIndexBuffer
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {ArrayBuffer} initialDataOrSize - [description]
|
||||
* @param {integer} bufferUsage - [description]
|
||||
* @param {ArrayBuffer} initialDataOrSize - It's either ArrayBuffer or an integer indicating the size of the vbo
|
||||
* @param {integer} bufferUsage - How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW
|
||||
*
|
||||
* @return {WebGLBuffer} [description]
|
||||
* @return {WebGLBuffer} Raw index buffer
|
||||
*/
|
||||
createIndexBuffer: function (initialDataOrSize, bufferUsage)
|
||||
{
|
||||
|
@ -1297,13 +1312,20 @@ var WebGLRenderer = new Class({
|
|||
*/
|
||||
deleteTexture: function (texture)
|
||||
{
|
||||
var index = this.nativeTextures.indexOf(texture);
|
||||
|
||||
if (index !== -1)
|
||||
{
|
||||
SpliceOne(this.nativeTextures, index);
|
||||
}
|
||||
|
||||
this.gl.deleteTexture(texture);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Wrapper for deleting a raw WebGLFramebuffer
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#deleteFramebuffer
|
||||
* @since 3.0.0
|
||||
|
@ -1337,7 +1359,7 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Wrapper for deleting a vertex or index buffer
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#deleteBuffer
|
||||
* @since 3.0.0
|
||||
|
@ -1356,7 +1378,8 @@ var WebGLRenderer = new Class({
|
|||
/* Rendering Functions */
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Handles any clipping needed by the camera and renders the background
|
||||
* color if a color is visible.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#preRenderCamera
|
||||
* @since 3.0.0
|
||||
|
@ -1393,7 +1416,8 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Renders the foreground camera effects like flash and fading.
|
||||
* It resets the current scissor state.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#postRenderCamera
|
||||
* @since 3.0.0
|
||||
|
@ -1416,7 +1440,7 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Clears the current vertex buffer and updates pipelines.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#preRender
|
||||
* @since 3.0.0
|
||||
|
@ -1555,9 +1579,7 @@ var WebGLRenderer = new Class({
|
|||
* @since 3.0.0
|
||||
*
|
||||
* @param {HTMLCanvasElement} srcCanvas - [description]
|
||||
* @param {WebGLTexture} dstTexture - [description]
|
||||
* @param {boolean} shouldReallocate - [description]
|
||||
* @param {integer} scaleMode - [description]
|
||||
* @param {WebGLTexture} [dstTexture] - [description]
|
||||
*
|
||||
* @return {WebGLTexture} [description]
|
||||
*/
|
||||
|
@ -1580,16 +1602,10 @@ var WebGLRenderer = new Class({
|
|||
{
|
||||
this.setTexture2D(dstTexture, 0);
|
||||
|
||||
// if (!shouldReallocate && dstTexture.width >= srcCanvas.width || dstTexture.height >= srcCanvas.height)
|
||||
// {
|
||||
// gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, srcCanvas.width, srcCanvas.height, gl.RGBA, gl.UNSIGNED_BYTE, srcCanvas);
|
||||
// }
|
||||
// else
|
||||
{
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, srcCanvas);
|
||||
dstTexture.width = srcCanvas.width;
|
||||
dstTexture.height = srcCanvas.height;
|
||||
}
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, srcCanvas);
|
||||
|
||||
dstTexture.width = srcCanvas.width;
|
||||
dstTexture.height = srcCanvas.height;
|
||||
|
||||
this.setTexture2D(null, 0);
|
||||
}
|
||||
|
@ -1690,17 +1706,17 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Sets uniform of a WebGLProgram
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setFloat4
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {WebGLProgram} program - [description]
|
||||
* @param {string} name - [description]
|
||||
* @param {float} x - [description]
|
||||
* @param {float} y - [description]
|
||||
* @param {float} z - [description]
|
||||
* @param {float} w - [description]
|
||||
* @param {WebGLProgram} program - Target program
|
||||
* @param {string} name - Name of the uniform
|
||||
* @param {float} x - X component
|
||||
* @param {float} y - Y component
|
||||
* @param {float} z - Z component
|
||||
* @param {float} w - W component
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
||||
*/
|
||||
|
@ -1780,17 +1796,17 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Sets uniform of a WebGLProgram
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setInt4
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {WebGLProgram} program - [description]
|
||||
* @param {string} name - [description]
|
||||
* @param {integer} x - [description]
|
||||
* @param {integer} y - [description]
|
||||
* @param {integer} z - [description]
|
||||
* @param {integer} w - [description]
|
||||
* @param {WebGLProgram} program - Target Program
|
||||
* @param {string} name - Name of the uniform
|
||||
* @param {integer} x - X component
|
||||
* @param {integer} y - Y component
|
||||
* @param {integer} z - Z component
|
||||
* @param {integer} w - W component
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
||||
*/
|
||||
|
@ -1848,15 +1864,15 @@ var WebGLRenderer = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Sets uniform of a WebGLProgram
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.WebGLRenderer#setMatrix4
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {WebGLProgram} program - [description]
|
||||
* @param {string} name - [description]
|
||||
* @param {boolean} transpose - [description]
|
||||
* @param {Float32Array} matrix - [description]
|
||||
* @param {WebGLProgram} program - Target program
|
||||
* @param {string} name - Name of the uniform
|
||||
* @param {boolean} transpose - Is the matrix transposed
|
||||
* @param {Float32Array} matrix - Matrix data
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
|
||||
*/
|
||||
|
@ -1881,12 +1897,14 @@ var WebGLRenderer = new Class({
|
|||
for (var key in this.pipelines)
|
||||
{
|
||||
this.pipelines[key].destroy();
|
||||
|
||||
delete this.pipelines[key];
|
||||
}
|
||||
|
||||
for (var index = 0; index < this.nativeTextures.length; ++index)
|
||||
{
|
||||
this.deleteTexture(this.nativeTextures[index]);
|
||||
|
||||
delete this.nativeTextures[index];
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,17 @@ var WebGLPipeline = require('../WebGLPipeline');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* BitmapMaskPipeline handles all bitmap masking rendering in WebGL. It works by using
|
||||
* sampling two texture on the fragment shader and using the fragment's alpha to clip the region.
|
||||
* The config properties are:
|
||||
* - game: Current game instance.
|
||||
* - renderer: Current WebGL renderer.
|
||||
* - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES.
|
||||
* Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants).
|
||||
* - vertShader: Source for vertex shader as a string.
|
||||
* - fragShader: Source for fragment shader as a string.
|
||||
* - vertexCapacity: The amount of vertices that shall be allocated
|
||||
* - vertexSize: The size of a single vertex in bytes.
|
||||
*
|
||||
* @class BitmapMaskPipeline
|
||||
* @extends Phaser.Renderer.WebGL.WebGLPipeline
|
||||
|
@ -20,7 +30,7 @@ var WebGLPipeline = require('../WebGLPipeline');
|
|||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {object} config - [description]
|
||||
* @param {object} config - Used for overriding shader an pipeline properties if extending this pipeline.
|
||||
*/
|
||||
var BitmapMaskPipeline = new Class({
|
||||
|
||||
|
@ -58,7 +68,7 @@ var BitmapMaskPipeline = new Class({
|
|||
});
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Float32 view of the array buffer containing the pipeline's vertices.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#vertexViewF32
|
||||
* @type {Float32Array}
|
||||
|
@ -67,7 +77,7 @@ var BitmapMaskPipeline = new Class({
|
|||
this.vertexViewF32 = new Float32Array(this.vertexData);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Size of the batch.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#maxQuads
|
||||
* @type {number}
|
||||
|
@ -77,7 +87,8 @@ var BitmapMaskPipeline = new Class({
|
|||
this.maxQuads = 1;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Dirty flag to check if resolution properties need to be updated on the
|
||||
* masking shader.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#resolutionDirty
|
||||
* @type {boolean}
|
||||
|
@ -88,7 +99,8 @@ var BitmapMaskPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Called every time the pipeline needs to be used.
|
||||
* It binds all necessary resources.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#onBind
|
||||
* @since 3.0.0
|
||||
|
@ -133,13 +145,14 @@ var BitmapMaskPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Binds necessary resources and renders the mask to a separated framebuffer.
|
||||
* The framebuffer for the masked object is also bound for further use.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#beginMask
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.GameObject} mask - [description]
|
||||
* @param {Phaser.GameObjects.GameObject} maskedObject - [description]
|
||||
* @param {Phaser.GameObjects.GameObject} mask - GameObject used as mask.
|
||||
* @param {Phaser.GameObjects.GameObject} maskedObject - GameObject masked by the mask GameObject.
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
||||
*/
|
||||
beginMask: function (mask, maskedObject, camera)
|
||||
|
@ -170,12 +183,15 @@ var BitmapMaskPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* The masked game object's framebuffer is unbound and it's texture
|
||||
* is bound together with the mask texture and the mask shader and
|
||||
* a draw call with a single quad is processed. Here is where the
|
||||
* masking effect is applied.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#endMask
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.GameObject} mask - [description]
|
||||
* @param {Phaser.GameObjects.GameObject} mask - GameObject used as a mask.
|
||||
*/
|
||||
endMask: function (mask)
|
||||
{
|
||||
|
|
|
@ -37,7 +37,17 @@ var pathArray = [];
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* The FlatTintPipeline is used for rendering flat colored shapes.
|
||||
* Mostly used by the Graphics game object.
|
||||
* The config properties are:
|
||||
* - game: Current game instance.
|
||||
* - renderer: Current WebGL renderer.
|
||||
* - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES.
|
||||
* Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants).
|
||||
* - vertShader: Source for vertex shader as a string.
|
||||
* - fragShader: Source for fragment shader as a string.
|
||||
* - vertexCapacity: The amount of vertices that shall be allocated
|
||||
* - vertexSize: The size of a single vertex in bytes.
|
||||
*
|
||||
* @class FlatTintPipeline
|
||||
* @extends Phaser.Renderer.WebGL.WebGLPipeline
|
||||
|
@ -45,7 +55,7 @@ var pathArray = [];
|
|||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {object} config - [description]
|
||||
* @param {object} config - Used for overriding shader an pipeline properties if extending this pipeline.
|
||||
*/
|
||||
var FlatTintPipeline = new Class({
|
||||
|
||||
|
@ -91,7 +101,7 @@ var FlatTintPipeline = new Class({
|
|||
});
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Float32 view of the array buffer containing the pipeline's vertices.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#vertexViewF32
|
||||
* @type {Float32Array}
|
||||
|
@ -100,7 +110,7 @@ var FlatTintPipeline = new Class({
|
|||
this.vertexViewF32 = new Float32Array(this.vertexData);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Uint32 view of the array buffer containing the pipeline's vertices.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#vertexViewU32
|
||||
* @type {Uint32Array}
|
||||
|
@ -109,7 +119,7 @@ var FlatTintPipeline = new Class({
|
|||
this.vertexViewU32 = new Uint32Array(this.vertexData);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Used internally to draw triangles
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#tempTriangle
|
||||
* @type {array}
|
||||
|
@ -123,7 +133,7 @@ var FlatTintPipeline = new Class({
|
|||
];
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Used internally by for triangulating a polyong
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#polygonCache
|
||||
* @type {array}
|
||||
|
@ -172,29 +182,29 @@ var FlatTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Pushes a rectangle into the vertex batch
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchFillRect
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {float} srcX - [description]
|
||||
* @param {float} srcY - [description]
|
||||
* @param {float} srcScaleX - [description]
|
||||
* @param {float} srcScaleY - [description]
|
||||
* @param {float} srcRotation - [description]
|
||||
* @param {float} x - [description]
|
||||
* @param {float} y - [description]
|
||||
* @param {float} width - [description]
|
||||
* @param {float} height - [description]
|
||||
* @param {integer} fillColor - [description]
|
||||
* @param {float} fillAlpha - [description]
|
||||
* @param {float} a1 - [description]
|
||||
* @param {float} b1 - [description]
|
||||
* @param {float} c1 - [description]
|
||||
* @param {float} d1 - [description]
|
||||
* @param {float} e1 - [description]
|
||||
* @param {float} f1 - [description]
|
||||
* @param {Float32Array} currentMatrix - [description]
|
||||
* @param {float} srcX - Graphics horizontal component for translation
|
||||
* @param {float} srcY - Graphics vertical component for translation
|
||||
* @param {float} srcScaleX - Graphics horizontal component for scale
|
||||
* @param {float} srcScaleY - Graphics vertical component for scale
|
||||
* @param {float} srcRotation - Graphics rotation
|
||||
* @param {float} x - Horiztonal top left coordinate of the rectangle
|
||||
* @param {float} y - Vertical top left coordinate of the rectangle
|
||||
* @param {float} width - Width of the rectangle
|
||||
* @param {float} height - Height of the rectangle
|
||||
* @param {integer} fillColor - RGB color packed as a uint
|
||||
* @param {float} fillAlpha - Alpha represented as float
|
||||
* @param {float} a1 - Matrix stack top a component
|
||||
* @param {float} b1 - Matrix stack top b component
|
||||
* @param {float} c1 - Matrix stack top c component
|
||||
* @param {float} d1 - Matrix stack top d component
|
||||
* @param {float} e1 - Matrix stack top e component
|
||||
* @param {float} f1 - Matrix stack top f component
|
||||
* @param {Float32Array} currentMatrix - Parent matrix, generally used by containers
|
||||
*/
|
||||
batchFillRect: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x, y, width, height, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
|
||||
{
|
||||
|
@ -260,26 +270,26 @@ var FlatTintPipeline = new Class({
|
|||
* @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchFillTriangle
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {float} srcX - [description]
|
||||
* @param {float} srcY - [description]
|
||||
* @param {float} srcScaleX - [description]
|
||||
* @param {float} srcScaleY - [description]
|
||||
* @param {float} srcRotation - [description]
|
||||
* @param {float} x0 - [description]
|
||||
* @param {float} y0 - [description]
|
||||
* @param {float} x1 - [description]
|
||||
* @param {float} y1 - [description]
|
||||
* @param {float} x2 - [description]
|
||||
* @param {float} y2 - [description]
|
||||
* @param {integer} fillColor - [description]
|
||||
* @param {float} fillAlpha - [description]
|
||||
* @param {float} a1 - [description]
|
||||
* @param {float} b1 - [description]
|
||||
* @param {float} c1 - [description]
|
||||
* @param {float} d1 - [description]
|
||||
* @param {float} e1 - [description]
|
||||
* @param {float} f1 - [description]
|
||||
* @param {Float32Array} currentMatrix - [description]
|
||||
* @param {float} srcX - Graphics horizontal component for translation
|
||||
* @param {float} srcY - Graphics vertical component for translation
|
||||
* @param {float} srcScaleX - Graphics horizontal component for scale
|
||||
* @param {float} srcScaleY - Graphics vertical component for scale
|
||||
* @param {float} srcRotation - Graphics rotation
|
||||
* @param {float} x0 - Point 0 x coordinate
|
||||
* @param {float} y0 - Point 0 y coordinate
|
||||
* @param {float} x1 - Point 1 x coordinate
|
||||
* @param {float} y1 - Point 1 y coordinate
|
||||
* @param {float} x2 - Point 2 x coordinate
|
||||
* @param {float} y2 - Point 2 y coordinate
|
||||
* @param {integer} fillColor - RGB color packed as a uint
|
||||
* @param {float} fillAlpha - Alpha represented as float
|
||||
* @param {float} a1 - Matrix stack top a component
|
||||
* @param {float} b1 - Matrix stack top b component
|
||||
* @param {float} c1 - Matrix stack top c component
|
||||
* @param {float} d1 - Matrix stack top d component
|
||||
* @param {float} e1 - Matrix stack top e component
|
||||
* @param {float} f1 - Matrix stack top f component
|
||||
* @param {Float32Array} currentMatrix - Parent matrix, generally used by containers
|
||||
*/
|
||||
batchFillTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
|
||||
{
|
||||
|
@ -332,27 +342,27 @@ var FlatTintPipeline = new Class({
|
|||
* @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchStrokeTriangle
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {float} srcX - [description]
|
||||
* @param {float} srcY - [description]
|
||||
* @param {float} srcScaleX - [description]
|
||||
* @param {float} srcScaleY - [description]
|
||||
* @param {float} srcRotation - [description]
|
||||
* @param {float} srcX - Graphics horizontal component for translation
|
||||
* @param {float} srcY - Graphics vertical component for translation
|
||||
* @param {float} srcScaleX - Graphics horizontal component for scale
|
||||
* @param {float} srcScaleY - Graphics vertical component for scale
|
||||
* @param {float} srcRotation - Graphics rotation
|
||||
* @param {float} x0 - [description]
|
||||
* @param {float} y0 - [description]
|
||||
* @param {float} x1 - [description]
|
||||
* @param {float} y1 - [description]
|
||||
* @param {float} x2 - [description]
|
||||
* @param {float} y2 - [description]
|
||||
* @param {float} lineWidth - [description]
|
||||
* @param {integer} lineColor - [description]
|
||||
* @param {float} lineAlpha - [description]
|
||||
* @param {float} a - [description]
|
||||
* @param {float} b - [description]
|
||||
* @param {float} c - [description]
|
||||
* @param {float} d - [description]
|
||||
* @param {float} e - [description]
|
||||
* @param {float} f - [description]
|
||||
* @param {Float32Array} currentMatrix - [description]
|
||||
* @param {float} lineWidth - Size of the line as a float value
|
||||
* @param {integer} lineColor - RGB color packed as a uint
|
||||
* @param {float} lineAlpha - Alpha represented as float
|
||||
* @param {float} a - Matrix stack top a component
|
||||
* @param {float} b - Matrix stack top b component
|
||||
* @param {float} c - Matrix stack top c component
|
||||
* @param {float} d - Matrix stack top d component
|
||||
* @param {float} e - Matrix stack top e component
|
||||
* @param {float} f - Matrix stack top f component
|
||||
* @param {Float32Array} currentMatrix - Parent matrix, generally used by containers
|
||||
*/
|
||||
batchStrokeTriangle: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, x0, y0, x1, y1, x2, y2, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, currentMatrix)
|
||||
{
|
||||
|
@ -394,21 +404,21 @@ var FlatTintPipeline = new Class({
|
|||
* @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchFillPath
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {float} srcX - [description]
|
||||
* @param {float} srcY - [description]
|
||||
* @param {float} srcScaleX - [description]
|
||||
* @param {float} srcScaleY - [description]
|
||||
* @param {float} srcRotation - [description]
|
||||
* @param {float} path - [description]
|
||||
* @param {integer} fillColor - [description]
|
||||
* @param {float} fillAlpha - [description]
|
||||
* @param {float} a1 - [description]
|
||||
* @param {float} b1 - [description]
|
||||
* @param {float} c1 - [description]
|
||||
* @param {float} d1 - [description]
|
||||
* @param {float} e1 - [description]
|
||||
* @param {float} f1 - [description]
|
||||
* @param {Float32Array} currentMatrix - [description]
|
||||
* @param {float} srcX - Graphics horizontal component for translation
|
||||
* @param {float} srcY - Graphics vertical component for translation
|
||||
* @param {float} srcScaleX - Graphics horizontal component for scale
|
||||
* @param {float} srcScaleY - Graphics vertical component for scale
|
||||
* @param {float} srcRotation - Graphics rotation
|
||||
* @param {float} path - Collection of points that represent the path
|
||||
* @param {integer} fillColor - RGB color packed as a uint
|
||||
* @param {float} fillAlpha - Alpha represented as float
|
||||
* @param {float} a1 - Matrix stack top a component
|
||||
* @param {float} b1 - Matrix stack top b component
|
||||
* @param {float} c1 - Matrix stack top c component
|
||||
* @param {float} d1 - Matrix stack top d component
|
||||
* @param {float} e1 - Matrix stack top e component
|
||||
* @param {float} f1 - Matrix stack top f component
|
||||
* @param {Float32Array} currentMatrix - Parent matrix, generally used by containers
|
||||
*/
|
||||
batchFillPath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, fillColor, fillAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
|
||||
{
|
||||
|
@ -496,23 +506,23 @@ var FlatTintPipeline = new Class({
|
|||
* @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchStrokePath
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {float} srcX - [description]
|
||||
* @param {float} srcY - [description]
|
||||
* @param {float} srcScaleX - [description]
|
||||
* @param {float} srcScaleY - [description]
|
||||
* @param {float} srcRotation - [description]
|
||||
* @param {float} srcX - Graphics horizontal component for translation
|
||||
* @param {float} srcY - Graphics vertical component for translation
|
||||
* @param {float} srcScaleX - Graphics horizontal component for scale
|
||||
* @param {float} srcScaleY - Graphics vertical component for scale
|
||||
* @param {float} srcRotation - Graphics rotation
|
||||
* @param {array} path - [description]
|
||||
* @param {float} lineWidth - [description]
|
||||
* @param {integer} lineColor - [description]
|
||||
* @param {float} lineAlpha - [description]
|
||||
* @param {float} a - [description]
|
||||
* @param {float} b - [description]
|
||||
* @param {float} c - [description]
|
||||
* @param {float} d - [description]
|
||||
* @param {float} e - [description]
|
||||
* @param {float} f - [description]
|
||||
* @param {boolean} isLastPath - [description]
|
||||
* @param {Float32Array} currentMatrix - [description]
|
||||
* @param {integer} lineColor - RGB color packed as a uint
|
||||
* @param {float} lineAlpha - Alpha represented as float
|
||||
* @param {float} a - Matrix stack top a component
|
||||
* @param {float} b - Matrix stack top b component
|
||||
* @param {float} c - Matrix stack top c component
|
||||
* @param {float} d - Matrix stack top d component
|
||||
* @param {float} e - Matrix stack top e component
|
||||
* @param {float} f - Matrix stack top f component
|
||||
* @param {boolean} isLastPath - Indicates if the path should be closed
|
||||
* @param {Float32Array} currentMatrix - Parent matrix, generally used by containers
|
||||
*/
|
||||
batchStrokePath: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, path, lineWidth, lineColor, lineAlpha, a, b, c, d, e, f, isLastPath, currentMatrix)
|
||||
{
|
||||
|
@ -589,27 +599,27 @@ var FlatTintPipeline = new Class({
|
|||
* @method Phaser.Renderer.WebGL.Pipelines.FlatTintPipeline#batchLine
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {float} srcX - [description]
|
||||
* @param {float} srcY - [description]
|
||||
* @param {float} srcScaleX - [description]
|
||||
* @param {float} srcScaleY - [description]
|
||||
* @param {float} srcRotation - [description]
|
||||
* @param {float} ax - [description]
|
||||
* @param {float} ay - [description]
|
||||
* @param {float} bx - [description]
|
||||
* @param {float} by - [description]
|
||||
* @param {float} aLineWidth - [description]
|
||||
* @param {float} bLineWidth - [description]
|
||||
* @param {integer} aLineColor - [description]
|
||||
* @param {integer} bLineColor - [description]
|
||||
* @param {float} lineAlpha - [description]
|
||||
* @param {float} a1 - [description]
|
||||
* @param {float} b1 - [description]
|
||||
* @param {float} c1 - [description]
|
||||
* @param {float} d1 - [description]
|
||||
* @param {float} e1 - [description]
|
||||
* @param {float} f1 - [description]
|
||||
* @param {Float32Array} currentMatrix - [description]
|
||||
* @param {float} srcX - Graphics horizontal component for translation
|
||||
* @param {float} srcY - Graphics vertical component for translation
|
||||
* @param {float} srcScaleX - Graphics horizontal component for scale
|
||||
* @param {float} srcScaleY - Graphics vertical component for scale
|
||||
* @param {float} srcRotation - Graphics rotation
|
||||
* @param {float} ax - X coordinate to the start of the line
|
||||
* @param {float} ay - Y coordinate to the start of the line
|
||||
* @param {float} bx - X coordinate to the end of the line
|
||||
* @param {float} by - Y coordinate to the end of the line
|
||||
* @param {float} aLineWidth - Width of the start of the line
|
||||
* @param {float} bLineWidth - Width of the end of the line
|
||||
* @param {integer} aLineColor - RGB color packed as a uint
|
||||
* @param {integer} bLineColor - RGB color packed as a uint
|
||||
* @param {float} lineAlpha - Alpha represented as float
|
||||
* @param {float} a1 - Matrix stack top a component
|
||||
* @param {float} b1 - Matrix stack top b component
|
||||
* @param {float} c1 - Matrix stack top c component
|
||||
* @param {float} d1 - Matrix stack top d component
|
||||
* @param {float} e1 - Matrix stack top e component
|
||||
* @param {float} f1 - Matrix stack top f component
|
||||
* @param {Float32Array} currentMatrix - Parent matrix, generally used by containers
|
||||
*/
|
||||
batchLine: function (srcX, srcY, srcScaleX, srcScaleY, srcRotation, ax, ay, bx, by, aLineWidth, bLineWidth, aLineColor, bLineColor, lineAlpha, a1, b1, c1, d1, e1, f1, currentMatrix)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,9 @@ var LIGHT_COUNT = 10;
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* ForwardDiffuseLightPipeline implements a forward rendering approach for 2D lights.
|
||||
* This pipeline extends TextureTintPipeline so it implements all it's rendering functions
|
||||
* and batching system.
|
||||
*
|
||||
* @class ForwardDiffuseLightPipeline
|
||||
* @extends Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline
|
||||
|
@ -37,7 +39,7 @@ var ForwardDiffuseLightPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* This function binds it's base class resources and this lights 2D resources.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#onBind
|
||||
* @override
|
||||
|
@ -61,7 +63,7 @@ var ForwardDiffuseLightPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* This function sets all the needed resources for each camera pass.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.ForwardDiffuseLightPipeline#onRender
|
||||
* @since 3.0.0
|
||||
|
|
|
@ -14,7 +14,17 @@ var WebGLPipeline = require('../WebGLPipeline');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* [description]
|
||||
* TextureTintPipeline implements the rendering infrastructure
|
||||
* for displaying textured objects
|
||||
* The config properties are:
|
||||
* - game: Current game instance.
|
||||
* - renderer: Current WebGL renderer.
|
||||
* - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES.
|
||||
* Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants).
|
||||
* - vertShader: Source for vertex shader as a string.
|
||||
* - fragShader: Source for fragment shader as a string.
|
||||
* - vertexCapacity: The amount of vertices that shall be allocated
|
||||
* - vertexSize: The size of a single vertex in bytes.
|
||||
*
|
||||
* @class TextureTintPipeline
|
||||
* @extends Phaser.Renderer.WebGL.WebGLPipeline
|
||||
|
@ -76,7 +86,7 @@ var TextureTintPipeline = new Class({
|
|||
});
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Float32 view of the array buffer containing the pipeline's vertices.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#vertexViewF32
|
||||
* @type {Float32Array}
|
||||
|
@ -85,7 +95,7 @@ var TextureTintPipeline = new Class({
|
|||
this.vertexViewF32 = new Float32Array(this.vertexData);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Uint32 view of the array buffer containing the pipeline's vertices.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#vertexViewU32
|
||||
* @type {Uint32Array}
|
||||
|
@ -94,7 +104,7 @@ var TextureTintPipeline = new Class({
|
|||
this.vertexViewU32 = new Uint32Array(this.vertexData);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Size of the batch.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#maxQuads
|
||||
* @type {integer}
|
||||
|
@ -104,7 +114,7 @@ var TextureTintPipeline = new Class({
|
|||
this.maxQuads = 2000;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Collection of batch information
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batches
|
||||
* @type {array}
|
||||
|
@ -116,13 +126,14 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Assigns a texture to the current batch. If a texture is already set it creates
|
||||
* a new batch object.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#setTexture2D
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param {WebGLTexture} texture - [description]
|
||||
* @param {integer} textureUnit - [description]
|
||||
* @param {WebGLTexture} texture - WebGLTexture that will be assigned to the current batch.
|
||||
* @param {integer} textureUnit - Texture unit to which the texture needs to be bound.
|
||||
*
|
||||
* @return {Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline} [description]
|
||||
*/
|
||||
|
@ -167,7 +178,10 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Creates a new batch object and pushes it to a batch array.
|
||||
* The batch object contains information relevant to the current
|
||||
* vertex batch like the offset in the vertex buffer, vertex count and
|
||||
* the textures used by that batch.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#pushBatch
|
||||
* @since 3.1.0
|
||||
|
@ -184,7 +198,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Binds, uploads resources and processes all batches generating draw calls.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#flush
|
||||
* @since 3.1.0
|
||||
|
@ -284,7 +298,8 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Called every time the pipeline needs to be used.
|
||||
* It binds all necessary resources.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#onBind
|
||||
* @since 3.0.0
|
||||
|
@ -325,7 +340,8 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Renders immediately a static tilemap. This function won't use
|
||||
* the batching functionality of the pipieline.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#drawStaticTilemapLayer
|
||||
* @since 3.0.0
|
||||
|
@ -361,7 +377,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Renders contents of a ParticleEmitterManager. It'll batch all particles if possible.
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#drawEmitterManager
|
||||
* @since 3.0.0
|
||||
|
@ -577,7 +593,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Batches blitter game object
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#drawBlitter
|
||||
* @since 3.0.0
|
||||
|
@ -737,7 +753,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Batches Sprite game object
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchSprite
|
||||
* @since 3.0.0
|
||||
|
@ -910,7 +926,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Batches Mesh game object
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchMesh
|
||||
* @since 3.0.0
|
||||
|
@ -1041,7 +1057,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Batches BitmapText game object
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchBitmapText
|
||||
* @since 3.0.0
|
||||
|
@ -1318,7 +1334,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Batches DynamicBitmapText game object
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchDynamicBitmapText
|
||||
* @since 3.0.0
|
||||
|
@ -1668,7 +1684,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Batches Text game object
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchText
|
||||
* @since 3.0.0
|
||||
|
@ -1704,7 +1720,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Batches DynamicTilemapLayer game object
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchDynamicTilemapLayer
|
||||
* @since 3.0.0
|
||||
|
@ -1762,7 +1778,7 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Batches TileSprite game object
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchTileSprite
|
||||
* @since 3.0.0
|
||||
|
@ -1799,40 +1815,40 @@ var TextureTintPipeline = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
* Generic function for batching a textured quad
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchTexture
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.GameObject} gameObject - [description]
|
||||
* @param {WebGLTexture} texture - [description]
|
||||
* @param {integer} textureWidth - [description]
|
||||
* @param {integer} textureHeight - [description]
|
||||
* @param {float} srcX - [description]
|
||||
* @param {float} srcY - [description]
|
||||
* @param {float} srcWidth - [description]
|
||||
* @param {float} srcHeight - [description]
|
||||
* @param {float} scaleX - [description]
|
||||
* @param {float} scaleY - [description]
|
||||
* @param {float} rotation - [description]
|
||||
* @param {boolean} flipX - [description]
|
||||
* @param {boolean} flipY - [description]
|
||||
* @param {float} scrollFactorX - [description]
|
||||
* @param {float} scrollFactorY - [description]
|
||||
* @param {float} displayOriginX - [description]
|
||||
* @param {float} displayOriginY - [description]
|
||||
* @param {float} frameX - [description]
|
||||
* @param {float} frameY - [description]
|
||||
* @param {float} frameWidth - [description]
|
||||
* @param {float} frameHeight - [description]
|
||||
* @param {integer} tintTL - [description]
|
||||
* @param {integer} tintTR - [description]
|
||||
* @param {integer} tintBL - [description]
|
||||
* @param {integer} tintBR - [description]
|
||||
* @param {float} uOffset - [description]
|
||||
* @param {float} vOffset - [description]
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
||||
* @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description]
|
||||
* @param {Phaser.GameObjects.GameObject} gameObject - Source GameObject
|
||||
* @param {WebGLTexture} texture - Raw WebGLTexture associated with the quad
|
||||
* @param {integer} textureWidth - Real texture width
|
||||
* @param {integer} textureHeight - Real texture height
|
||||
* @param {float} srcX - X coordinate of the quad
|
||||
* @param {float} srcY - Y coordinate of the quad
|
||||
* @param {float} srcWidth - Width of the quad
|
||||
* @param {float} srcHeight - Height of the quad
|
||||
* @param {float} scaleX - X component of scale
|
||||
* @param {float} scaleY - Y component of scale
|
||||
* @param {float} rotation - Rotation of the quad
|
||||
* @param {boolean} flipX - Indicates if the quad is horizontally flipped
|
||||
* @param {boolean} flipY - Indicates if the quad is vertically flipped
|
||||
* @param {float} scrollFactorX - By which factor is the quad affected by the camera horizontal scroll
|
||||
* @param {float} scrollFactorY - By which factor is the quad effected by the camera vertical scroll
|
||||
* @param {float} displayOriginX - Horizontal origin in pixels
|
||||
* @param {float} displayOriginY - Vertical origin in pixels
|
||||
* @param {float} frameX - X coordinate of the texture frame
|
||||
* @param {float} frameY - Y coordinate of the texture frame
|
||||
* @param {float} frameWidth - Width of the texture frame
|
||||
* @param {float} frameHeight - Height of the texture frame
|
||||
* @param {integer} tintTL - Tint for top left
|
||||
* @param {integer} tintTR - Tint for top right
|
||||
* @param {integer} tintBL - Tint for bottom left
|
||||
* @param {integer} tintBR - Tint for bottom right
|
||||
* @param {float} uOffset - Horizontal offset on texture coordinate
|
||||
* @param {float} vOffset - Vertical offset on texture coordinate
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} camera - Current used camera
|
||||
* @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - Parent container
|
||||
*/
|
||||
batchTexture: function (
|
||||
gameObject,
|
||||
|
|
|
@ -4,15 +4,47 @@
|
|||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements a model view projection matrices.
|
||||
* Pipelines can implement this for doing 2D and 3D rendering.
|
||||
*/
|
||||
|
||||
var ModelViewProjection = {
|
||||
|
||||
/**
|
||||
* Dirty flag for checking if model matrix needs to be updated on GPU.
|
||||
*/
|
||||
modelMatrixDirty: false,
|
||||
|
||||
/**
|
||||
* Dirty flag for checking if view matrix needs to be updated on GPU.
|
||||
*/
|
||||
viewMatrixDirty: false,
|
||||
|
||||
/**
|
||||
* Dirty flag for checking if projection matrix needs to be updated on GPU.
|
||||
*/
|
||||
projectionMatrixDirty: false,
|
||||
|
||||
/**
|
||||
* Model matrix
|
||||
*/
|
||||
modelMatrix: null,
|
||||
|
||||
/**
|
||||
* View matrix
|
||||
*/
|
||||
viewMatrix: null,
|
||||
|
||||
/**
|
||||
* Projection matrix
|
||||
*/
|
||||
projectionMatrix: null,
|
||||
|
||||
/**
|
||||
* Initializes MVP matrices with an identity matrix
|
||||
*/
|
||||
mvpInit: function ()
|
||||
{
|
||||
this.modelMatrixDirty = true;
|
||||
|
@ -43,6 +75,9 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* If dirty flags are set then the matrices are uploaded to the GPU.
|
||||
*/
|
||||
mvpUpdate: function ()
|
||||
{
|
||||
var program = this.program;
|
||||
|
@ -68,6 +103,9 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads an identity matrix to the model matrix
|
||||
*/
|
||||
modelIdentity: function ()
|
||||
{
|
||||
var modelMatrix = this.modelMatrix;
|
||||
|
@ -94,6 +132,9 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Scale model matrix
|
||||
*/
|
||||
modelScale: function (x, y, z)
|
||||
{
|
||||
var modelMatrix = this.modelMatrix;
|
||||
|
@ -116,6 +157,9 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Translate model matrix
|
||||
*/
|
||||
modelTranslate: function (x, y, z)
|
||||
{
|
||||
var modelMatrix = this.modelMatrix;
|
||||
|
@ -130,6 +174,10 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Rotates the model matrix in the X axis.
|
||||
*/
|
||||
modelRotateX: function (radians)
|
||||
{
|
||||
var modelMatrix = this.modelMatrix;
|
||||
|
@ -158,6 +206,9 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Rotates the model matrix in the Y axis.
|
||||
*/
|
||||
modelRotateY: function (radians)
|
||||
{
|
||||
var modelMatrix = this.modelMatrix;
|
||||
|
@ -185,7 +236,10 @@ var ModelViewProjection = {
|
|||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Rotates the model matrix in the Z axis.
|
||||
*/
|
||||
modelRotateZ: function (radians)
|
||||
{
|
||||
var modelMatrix = this.modelMatrix;
|
||||
|
@ -214,6 +268,9 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads identity matrix into the view matrix
|
||||
*/
|
||||
viewIdentity: function ()
|
||||
{
|
||||
var viewMatrix = this.viewMatrix;
|
||||
|
@ -239,7 +296,10 @@ var ModelViewProjection = {
|
|||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Scales view matrix
|
||||
*/
|
||||
viewScale: function (x, y, z)
|
||||
{
|
||||
var viewMatrix = this.viewMatrix;
|
||||
|
@ -262,6 +322,9 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Translates view matrix
|
||||
*/
|
||||
viewTranslate: function (x, y, z)
|
||||
{
|
||||
var viewMatrix = this.viewMatrix;
|
||||
|
@ -275,7 +338,10 @@ var ModelViewProjection = {
|
|||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Rotates view matrix in the X axis.
|
||||
*/
|
||||
viewRotateX: function (radians)
|
||||
{
|
||||
var viewMatrix = this.viewMatrix;
|
||||
|
@ -303,7 +369,10 @@ var ModelViewProjection = {
|
|||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Rotates view matrix in the Y axis.
|
||||
*/
|
||||
viewRotateY: function (radians)
|
||||
{
|
||||
var viewMatrix = this.viewMatrix;
|
||||
|
@ -331,7 +400,10 @@ var ModelViewProjection = {
|
|||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Rotates view matrix in the Z axis.
|
||||
*/
|
||||
viewRotateZ: function (radians)
|
||||
{
|
||||
var viewMatrix = this.viewMatrix;
|
||||
|
@ -360,6 +432,9 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Loads a 2D view matrix (3x2 matrix) into a 4x4 view matrix
|
||||
*/
|
||||
viewLoad2D: function (matrix2D)
|
||||
{
|
||||
var vm = this.viewMatrix;
|
||||
|
@ -386,6 +461,10 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Copies a 4x4 matrix into the view matrix
|
||||
*/
|
||||
viewLoad: function (matrix)
|
||||
{
|
||||
var vm = this.viewMatrix;
|
||||
|
@ -411,7 +490,10 @@ var ModelViewProjection = {
|
|||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Loads identity matrix into the projection matrix.
|
||||
*/
|
||||
projIdentity: function ()
|
||||
{
|
||||
var projectionMatrix = this.projectionMatrix;
|
||||
|
@ -438,6 +520,9 @@ var ModelViewProjection = {
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets up an orthographics projection matrix
|
||||
*/
|
||||
projOrtho: function (left, right, bottom, top, near, far)
|
||||
{
|
||||
var projectionMatrix = this.projectionMatrix;
|
||||
|
@ -465,7 +550,10 @@ var ModelViewProjection = {
|
|||
this.projectionMatrixDirty = true;
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Sets up a perspective projection matrix
|
||||
*/
|
||||
projPersp: function (fovy, aspectRatio, near, far)
|
||||
{
|
||||
var projectionMatrix = this.projectionMatrix;
|
||||
|
|
|
@ -13,9 +13,9 @@ var UppercaseFirst = require('../utils/string/UppercaseFirst');
|
|||
* @function Phaser.Scenes.GetPhysicsPlugins
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Scenes.Systems} sys - [description]
|
||||
* @param {Phaser.Scenes.Systems} sys - The scene system to get the physics systems of.
|
||||
*
|
||||
* @return {array} [description]
|
||||
* @return {array} An array of Physics systems to start for this Scene.
|
||||
*/
|
||||
var GetPhysicsPlugins = function (sys)
|
||||
{
|
||||
|
|
|
@ -319,6 +319,11 @@ var SceneManager = new Class({
|
|||
data: data
|
||||
});
|
||||
|
||||
if (!this.isBooted)
|
||||
{
|
||||
this._data[key] = { data: data };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
203
src/textures/CanvasTexture.js
Normal file
203
src/textures/CanvasTexture.js
Normal file
|
@ -0,0 +1,203 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2018 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var Class = require('../utils/Class');
|
||||
var IsSizePowerOfTwo = require('../math/pow2/IsSizePowerOfTwo');
|
||||
var Texture = require('./Texture');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A Canvas Texture is a special kind of Texture that is backed by an HTML Canvas Element as its source.
|
||||
*
|
||||
* You can use the properties of this texture to draw to the canvas element directly, using all of the standard
|
||||
* canvas operations available in the browser. Any Game Object can be given this texture and will render with it.
|
||||
*
|
||||
* Note: When running under WebGL the Canvas Texture needs to re-generate its base WebGLTexture and reupload it to
|
||||
* the GPU every time you modify it, otherwise the changes you make to this texture will not be visible. To do this
|
||||
* you should call `CanvasTexture.refresh()` once you are finished with your changes to the canvas. Try and keep
|
||||
* this to a minimum, especially on large canvas sizes, or you may inadvertently thrash the GPU by constantly uploading
|
||||
* texture data to it. This restriction does not apply if using the Canvas Renderer.
|
||||
*
|
||||
* It starts with only one frame that covers the whole of the canvas. You can add further frames, that specify
|
||||
* sections of the canvas using the `add` method.
|
||||
*
|
||||
* Should you need to resize the canvas use the `setSize` method so that it accurately updates all of the underlying
|
||||
* texture data as well. Forgetting to do this (i.e. by changing the canvas size directly from your code) could cause
|
||||
* graphical errors.
|
||||
*
|
||||
* @class CanvasTexture
|
||||
* @extends Phaser.Textures.Texture
|
||||
* @memberOf Phaser.Textures
|
||||
* @constructor
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @param {Phaser.Textures.TextureManager} manager - A reference to the Texture Manager this Texture belongs to.
|
||||
* @param {string} key - The unique string-based key of this Texture.
|
||||
* @param {HTMLCanvasElement} source - The canvas element that is used as the base of this texture.
|
||||
* @param {integer} width - The width of the canvas.
|
||||
* @param {integer} height - The height of the canvas.
|
||||
*/
|
||||
var CanvasTexture = new Class({
|
||||
|
||||
Extends: Texture,
|
||||
|
||||
initialize:
|
||||
|
||||
function CanvasTexture (manager, key, source, width, height)
|
||||
{
|
||||
Texture.call(this, manager, key, source, width, height);
|
||||
|
||||
this.add('__BASE', 0, 0, 0, width, height);
|
||||
|
||||
/**
|
||||
* A reference to the Texture Source of this Canvas.
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#_source
|
||||
* @type {Phaser.Textures.TextureSource}
|
||||
* @private
|
||||
* @since 3.6.1
|
||||
*/
|
||||
this._source = this.frames['__BASE'].source;
|
||||
|
||||
/**
|
||||
* The source Canvas Element.
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#canvas
|
||||
* @readOnly
|
||||
* @type {HTMLCanvasElement}
|
||||
* @since 3.6.1
|
||||
*/
|
||||
this.canvas = this._source.image;
|
||||
|
||||
/**
|
||||
* The 2D Canvas Rendering Context.
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#canvas
|
||||
* @readOnly
|
||||
* @type {CanvasRenderingContext2D}
|
||||
* @since 3.6.1
|
||||
*/
|
||||
this.context = this.canvas.getContext('2d');
|
||||
|
||||
/**
|
||||
* The width of the Canvas.
|
||||
* This property is read-only, if you wish to change use `setSize`.
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#width
|
||||
* @readOnly
|
||||
* @type {integer}
|
||||
* @since 3.6.1
|
||||
*/
|
||||
this.width = width;
|
||||
|
||||
/**
|
||||
* The height of the Canvas.
|
||||
* This property is read-only, if you wish to change use `setSize`.
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#height
|
||||
* @readOnly
|
||||
* @type {integer}
|
||||
* @since 3.6.1
|
||||
*/
|
||||
this.height = height;
|
||||
},
|
||||
|
||||
/**
|
||||
* This should be called manually if you are running under WebGL.
|
||||
* It will refresh the WebGLTexture from the Canvas source. Only call this if you know that the
|
||||
* canvas has changed, as there is a significant GPU texture allocation cost involved in doing so.
|
||||
*
|
||||
* @method Phaser.Textures.CanvasTexture#refresh
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @return {Phaser.Textures.CanvasTexture} This CanvasTexture.
|
||||
*/
|
||||
refresh: function ()
|
||||
{
|
||||
this._source.update();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the Canvas Element.
|
||||
*
|
||||
* @method Phaser.Textures.CanvasTexture#getCanvas
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @return {HTMLCanvasElement} The Canvas DOM element this texture is using.
|
||||
*/
|
||||
getCanvas: function ()
|
||||
{
|
||||
return this.canvas;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the 2D Canvas Rendering Context.
|
||||
*
|
||||
* @method Phaser.Textures.CanvasTexture#getContext
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @return {CanvasRenderingContext2D} The Canvas Rendering Context this texture is using.
|
||||
*/
|
||||
getContext: function ()
|
||||
{
|
||||
return this.context;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clears this Canvas Texture, resetting it back to transparent.
|
||||
*
|
||||
* @method Phaser.Textures.CanvasTexture#clear
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @return {Phaser.Textures.CanvasTexture} The Canvas Texture.
|
||||
*/
|
||||
clear: function ()
|
||||
{
|
||||
this.context.clearRect(0, 0, this.width, this.height);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the size of this Canvas Texture.
|
||||
*
|
||||
* @method Phaser.Textures.CanvasTexture#setSize
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @param {integer} width - The new width of the Canvas.
|
||||
* @param {integer} [height] - The new height of the Canvas. If not given it will use the width as the height.
|
||||
*
|
||||
* @return {Phaser.Textures.CanvasTexture} The Canvas Texture.
|
||||
*/
|
||||
setSize: function (width, height)
|
||||
{
|
||||
if (height === undefined) { height = width; }
|
||||
|
||||
if (width !== this.width || height !== this.height)
|
||||
{
|
||||
// Update the Canvas
|
||||
this.canvas.width = width;
|
||||
this.canvas.height = height;
|
||||
|
||||
// Update the Texture Source
|
||||
this._source.width = width;
|
||||
this._source.height = height;
|
||||
this._source.isPowerOf2 = IsSizePowerOfTwo(width, height);
|
||||
|
||||
// Update the Frame
|
||||
this.frames['__BASE'].setSize(width, height, 0, 0);
|
||||
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = CanvasTexture;
|
|
@ -74,7 +74,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.cutX = x;
|
||||
this.cutX;
|
||||
|
||||
/**
|
||||
* Y position within the source image to cut from.
|
||||
|
@ -83,7 +83,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.cutY = y;
|
||||
this.cutY;
|
||||
|
||||
/**
|
||||
* The width of the area in the source image to cut.
|
||||
|
@ -92,7 +92,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.cutWidth = width;
|
||||
this.cutWidth;
|
||||
|
||||
/**
|
||||
* The height of the area in the source image to cut.
|
||||
|
@ -101,7 +101,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.cutHeight = height;
|
||||
this.cutHeight;
|
||||
|
||||
/**
|
||||
* The X rendering offset of this Frame, taking trim into account.
|
||||
|
@ -130,7 +130,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.width = width;
|
||||
this.width;
|
||||
|
||||
/**
|
||||
* The rendering height of this Frame, taking trim into account.
|
||||
|
@ -139,7 +139,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.height = height;
|
||||
this.height;
|
||||
|
||||
/**
|
||||
* Half the width, floored.
|
||||
|
@ -149,7 +149,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.halfWidth = Math.floor(width * 0.5);
|
||||
this.halfWidth;
|
||||
|
||||
/**
|
||||
* Half the height, floored.
|
||||
|
@ -159,7 +159,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.halfHeight = Math.floor(height * 0.5);
|
||||
this.halfHeight;
|
||||
|
||||
/**
|
||||
* The x center of this frame, floored.
|
||||
|
@ -168,7 +168,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.centerX = Math.floor(width / 2);
|
||||
this.centerX;
|
||||
|
||||
/**
|
||||
* The y center of this frame, floored.
|
||||
|
@ -177,7 +177,7 @@ var Frame = new Class({
|
|||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.centerY = Math.floor(height / 2);
|
||||
this.centerY;
|
||||
|
||||
/**
|
||||
* The horizontal pivot point of this Frame.
|
||||
|
@ -255,23 +255,23 @@ var Frame = new Class({
|
|||
*/
|
||||
this.data = {
|
||||
cut: {
|
||||
x: x,
|
||||
y: y,
|
||||
w: width,
|
||||
h: height,
|
||||
r: x + width,
|
||||
b: y + height
|
||||
x: 0,
|
||||
y: 0,
|
||||
w: 0,
|
||||
h: 0,
|
||||
r: 0,
|
||||
b: 0
|
||||
},
|
||||
trim: false,
|
||||
sourceSize: {
|
||||
w: width,
|
||||
h: height
|
||||
w: 0,
|
||||
h: 0
|
||||
},
|
||||
spriteSourceSize: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
w: width,
|
||||
h: height
|
||||
w: 0,
|
||||
h: 0
|
||||
},
|
||||
uvs: {
|
||||
x0: 0,
|
||||
|
@ -283,18 +283,83 @@ var Frame = new Class({
|
|||
x3: 0,
|
||||
y3: 0
|
||||
},
|
||||
radius: 0.5 * Math.sqrt(width * width + height * height),
|
||||
radius: 0,
|
||||
drawImage: {
|
||||
sx: x,
|
||||
sy: y,
|
||||
sWidth: width,
|
||||
sHeight: height,
|
||||
dWidth: width,
|
||||
dHeight: height
|
||||
sx: 0,
|
||||
sy: 0,
|
||||
sWidth: 0,
|
||||
sHeight: 0,
|
||||
dWidth: 0,
|
||||
dHeight: 0
|
||||
}
|
||||
};
|
||||
|
||||
this.updateUVs();
|
||||
this.setSize(width, height, x, y);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the width, height, x and y of this Frame.
|
||||
*
|
||||
* This is called automatically by the constructor
|
||||
* and should rarely be changed on-the-fly.
|
||||
*
|
||||
* @method Phaser.Textures.Frame#setSize
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @param {integer} width - The width of the frame before being trimmed.
|
||||
* @param {integer} height - The height of the frame before being trimmed.
|
||||
* @param {integer} [x=0] - The x coordinate of the top-left of this Frame.
|
||||
* @param {integer} [y=0] - The y coordinate of the top-left of this Frame.
|
||||
*
|
||||
* @return {Phaser.Textures.Frame} This Frame object.
|
||||
*/
|
||||
setSize: function (width, height, x, y)
|
||||
{
|
||||
if (x === undefined) { x = 0; }
|
||||
if (y === undefined) { y = 0; }
|
||||
|
||||
this.cutX = x;
|
||||
this.cutY = y;
|
||||
this.cutWidth = width;
|
||||
this.cutHeight = height;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.halfWidth = Math.floor(width * 0.5);
|
||||
this.halfHeight = Math.floor(height * 0.5);
|
||||
|
||||
this.centerX = Math.floor(width / 2);
|
||||
this.centerY = Math.floor(height / 2);
|
||||
|
||||
var data = this.data;
|
||||
var cut = data.cut;
|
||||
|
||||
cut.x = x;
|
||||
cut.y = y;
|
||||
cut.w = width;
|
||||
cut.h = height;
|
||||
cut.r = x + width;
|
||||
cut.b = y + height;
|
||||
|
||||
data.sourceSize.w = width;
|
||||
data.sourceSize.h = height;
|
||||
|
||||
data.spriteSourceSize.w = width;
|
||||
data.spriteSourceSize.h = height;
|
||||
|
||||
data.radius = 0.5 * Math.sqrt(width * width + height * height);
|
||||
|
||||
var drawImage = data.drawImage;
|
||||
|
||||
drawImage.sx = x;
|
||||
drawImage.sy = y;
|
||||
drawImage.sWidth = width;
|
||||
drawImage.sHeight = height;
|
||||
drawImage.dWidth = width;
|
||||
drawImage.dHeight = height;
|
||||
|
||||
return this.updateUVs();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,8 +10,8 @@ var TextureSource = require('./TextureSource');
|
|||
|
||||
/**
|
||||
* @classdesc
|
||||
* A Texture consists of a source, usually an Image from the Cache, or a Canvas, and a collection
|
||||
* of Frames. The Frames represent the different areas of the Texture. For example a texture atlas
|
||||
* A Texture consists of a source, usually an Image from the Cache, and a collection of Frames.
|
||||
* The Frames represent the different areas of the Texture. For example a texture atlas
|
||||
* may have many Frames, one for each element within the atlas. Where-as a single image would have
|
||||
* just one frame, that encompasses the whole image.
|
||||
*
|
||||
|
@ -419,6 +419,7 @@ var Texture = new Class({
|
|||
this.source = [];
|
||||
this.dataSource = [];
|
||||
this.frames = {};
|
||||
this.manager = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
*/
|
||||
|
||||
var CanvasPool = require('../display/canvas/CanvasPool');
|
||||
var CanvasTexture = require('./CanvasTexture');
|
||||
var Class = require('../utils/Class');
|
||||
var Color = require('../display/color/Color');
|
||||
var CONST = require('../const');
|
||||
var EventEmitter = require('eventemitter3');
|
||||
var GenerateTexture = require('../create/GenerateTexture');
|
||||
var GetValue = require('../utils/object/GetValue');
|
||||
|
@ -147,6 +149,73 @@ var TextureManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks the given texture key and throws a console.warn if the key is already in use, then returns false.
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#checkKey
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @param {string} key - The texture key to check.
|
||||
*
|
||||
* @return {boolean} `true` if it's safe to use the texture key, otherwise `false`.
|
||||
*/
|
||||
checkKey: function (key)
|
||||
{
|
||||
if (this.exists(key))
|
||||
{
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Texture key already in use: ' + key);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes a Texture from the Texture Manager and destroys it. This will immediately
|
||||
* clear all references to it from the Texture Manager, and if it has one, destroy its
|
||||
* WebGLTexture. This will emit a `removetexture` event.
|
||||
*
|
||||
* Note: If you have any Game Objects still using this texture they will start throwing
|
||||
* errors the next time they try to render. Make sure that removing the texture is the final
|
||||
* step when clearing down to avoid this.
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#remove
|
||||
* @since 3.6.1
|
||||
*
|
||||
* @param {(string|Phaser.Textures.Texture)} key - The key of the Texture to remove, or a reference to it.
|
||||
*
|
||||
* @return {Phaser.Textures.TextureManager} The Texture Manager.
|
||||
*/
|
||||
remove: function (key)
|
||||
{
|
||||
if (typeof key === 'string')
|
||||
{
|
||||
if (this.exists(key))
|
||||
{
|
||||
key = this.get(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn('No texture found matching key: ' + key);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
// By this point key should be a Texture, if not, the following fails anyway
|
||||
if (this.list.hasOwnProperty(key.key))
|
||||
{
|
||||
delete this.list[key.key];
|
||||
|
||||
key.destroy();
|
||||
|
||||
this.emit('removetexture', key.key);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a new Texture to the Texture Manager created from the given Base64 encoded data.
|
||||
*
|
||||
|
@ -158,27 +227,30 @@ var TextureManager = new Class({
|
|||
*/
|
||||
addBase64: function (key, data)
|
||||
{
|
||||
var _this = this;
|
||||
|
||||
var image = new Image();
|
||||
|
||||
image.onerror = function ()
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
_this.emit('onerror', key);
|
||||
};
|
||||
var _this = this;
|
||||
|
||||
image.onload = function ()
|
||||
{
|
||||
var texture = _this.create(key, image);
|
||||
var image = new Image();
|
||||
|
||||
Parser.Image(texture, 0);
|
||||
image.onerror = function ()
|
||||
{
|
||||
_this.emit('onerror', key);
|
||||
};
|
||||
|
||||
_this.emit('addtexture', key, texture);
|
||||
image.onload = function ()
|
||||
{
|
||||
var texture = _this.create(key, image);
|
||||
|
||||
_this.emit('onload', key, texture);
|
||||
};
|
||||
Parser.Image(texture, 0);
|
||||
|
||||
image.src = data;
|
||||
_this.emit('addtexture', key, texture);
|
||||
|
||||
_this.emit('onload', key, texture);
|
||||
};
|
||||
|
||||
image.src = data;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -191,21 +263,26 @@ var TextureManager = new Class({
|
|||
* @param {HTMLImageElement} source - The source Image element.
|
||||
* @param {HTMLImageElement} [dataSource] - An optional data Image element.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addImage: function (key, source, dataSource)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
var texture = null;
|
||||
|
||||
Parser.Image(texture, 0);
|
||||
|
||||
if (dataSource)
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
texture.setDataSource(dataSource);
|
||||
texture = this.create(key, source);
|
||||
|
||||
Parser.Image(texture, 0);
|
||||
|
||||
if (dataSource)
|
||||
{
|
||||
texture.setDataSource(dataSource);
|
||||
}
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
}
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
||||
|
@ -220,17 +297,24 @@ var TextureManager = new Class({
|
|||
* @param {string} key - The unique string-based key of the Texture.
|
||||
* @param {object} config - [description]
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
generate: function (key, config)
|
||||
{
|
||||
var canvas = CanvasPool.create(this, 1, 1);
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
var canvas = CanvasPool.create(this, 1, 1);
|
||||
|
||||
config.canvas = canvas;
|
||||
config.canvas = canvas;
|
||||
|
||||
GenerateTexture(config);
|
||||
GenerateTexture(config);
|
||||
|
||||
return this.addCanvas(key, canvas);
|
||||
return this.addCanvas(key, canvas);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -243,23 +327,28 @@ var TextureManager = new Class({
|
|||
* @since 3.0.0
|
||||
*
|
||||
* @param {string} key - The unique string-based key of the Texture.
|
||||
* @param {integer} width - The width of the Canvas element.
|
||||
* @param {integer} height - The height of the Canvas element.
|
||||
* @param {integer} [width=256]- The width of the Canvas element.
|
||||
* @param {integer} [height=256] - The height of the Canvas element.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.CanvasTexture} The Canvas Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
createCanvas: function (key, width, height)
|
||||
{
|
||||
if (width === undefined) { width = 256; }
|
||||
if (height === undefined) { height = 256; }
|
||||
|
||||
var canvas = CanvasPool.create(this, width, height);
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
var canvas = CanvasPool.create(this, width, height, CONST.CANVAS, true);
|
||||
|
||||
return this.addCanvas(key, canvas);
|
||||
return this.addCanvas(key, canvas);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Texture object from an existing Canvas element and adds
|
||||
* Creates a new Canvas Texture object from an existing Canvas element and adds
|
||||
* it to this Texture Manager.
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addCanvas
|
||||
|
@ -268,15 +357,20 @@ var TextureManager = new Class({
|
|||
* @param {string} key - The unique string-based key of the Texture.
|
||||
* @param {HTMLCanvasElement} source - The Canvas element to form the base of the new Texture.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.CanvasTexture} The Canvas Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addCanvas: function (key, source)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
var texture = null;
|
||||
|
||||
Parser.Canvas(texture, 0);
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
texture = new CanvasTexture(this, key, source, source.width, source.height);
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
this.list[key] = texture;
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
@ -292,7 +386,7 @@ var TextureManager = new Class({
|
|||
* @param {HTMLImageElement} source - The source Image element.
|
||||
* @param {object} data - The Texture Atlas data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addAtlas: function (key, source, data)
|
||||
{
|
||||
|
@ -319,29 +413,34 @@ var TextureManager = new Class({
|
|||
* @param {HTMLImageElement} source - The source Image element.
|
||||
* @param {object} data - The Texture Atlas data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addAtlasJSONArray: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
var texture = null;
|
||||
|
||||
if (Array.isArray(data))
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
var singleAtlasFile = (data.length === 1); // multi-pack with one atlas file for all images
|
||||
texture = this.create(key, source);
|
||||
|
||||
for (var i = 0; i < texture.source.length; i++)
|
||||
if (Array.isArray(data))
|
||||
{
|
||||
var atlasData = singleAtlasFile ? data[0] : data[i];
|
||||
var singleAtlasFile = (data.length === 1); // multi-pack with one atlas file for all images
|
||||
|
||||
Parser.JSONArray(texture, i, atlasData);
|
||||
for (var i = 0; i < texture.source.length; i++)
|
||||
{
|
||||
var atlasData = singleAtlasFile ? data[0] : data[i];
|
||||
|
||||
Parser.JSONArray(texture, i, atlasData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Parser.JSONArray(texture, 0, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Parser.JSONArray(texture, 0, data);
|
||||
}
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
this.emit('addtexture', key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
@ -358,25 +457,30 @@ var TextureManager = new Class({
|
|||
* @param {HTMLImageElement} source - The source Image element.
|
||||
* @param {object} data - The Texture Atlas data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addAtlasJSONHash: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
var texture = null;
|
||||
|
||||
if (Array.isArray(data))
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
for (var i = 0; i < data.length; i++)
|
||||
texture = this.create(key, source);
|
||||
|
||||
if (Array.isArray(data))
|
||||
{
|
||||
Parser.JSONHash(texture, i, data[i]);
|
||||
for (var i = 0; i < data.length; i++)
|
||||
{
|
||||
Parser.JSONHash(texture, i, data[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Parser.JSONHash(texture, 0, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Parser.JSONHash(texture, 0, data);
|
||||
}
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
this.emit('addtexture', key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
@ -392,15 +496,20 @@ var TextureManager = new Class({
|
|||
* @param {HTMLImageElement} source - The source Image element.
|
||||
* @param {object} data - The Texture Atlas data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addUnityAtlas: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
var texture = null;
|
||||
|
||||
Parser.UnityYAML(texture, 0, data);
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
texture = this.create(key, source);
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
Parser.UnityYAML(texture, 0, data);
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
@ -429,18 +538,23 @@ var TextureManager = new Class({
|
|||
* @param {HTMLImageElement} source - The source Image element.
|
||||
* @param {SpriteSheetConfig} config - The configuration object for this Sprite Sheet.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addSpriteSheet: function (key, source, config)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
var texture = null;
|
||||
|
||||
var width = texture.source[0].width;
|
||||
var height = texture.source[0].height;
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
texture = this.create(key, source);
|
||||
|
||||
Parser.SpriteSheet(texture, 0, 0, 0, width, height, config);
|
||||
var width = texture.source[0].width;
|
||||
var height = texture.source[0].height;
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
Parser.SpriteSheet(texture, 0, 0, 0, width, height, config);
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
@ -470,10 +584,15 @@ var TextureManager = new Class({
|
|||
* @param {string} key - The unique string-based key of the Texture.
|
||||
* @param {SpriteSheetFromAtlasConfig} config - The configuration object for this Sprite Sheet.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addSpriteSheetFromAtlas: function (key, config)
|
||||
{
|
||||
if (!this.checkKey(key))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var atlasKey = GetValue(config, 'atlas', null);
|
||||
var atlasFrame = GetValue(config, 'frame', null);
|
||||
|
||||
|
@ -516,25 +635,30 @@ var TextureManager = new Class({
|
|||
* @param {HTMLImageElement} source - The source Image element.
|
||||
* @param {object} data - The Texture Atlas XML data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addAtlasStarlingXML: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
var texture = null;
|
||||
|
||||
if (Array.isArray(data))
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
for (var i = 0; i < data.length; i++)
|
||||
texture = this.create(key, source);
|
||||
|
||||
if (Array.isArray(data))
|
||||
{
|
||||
Parser.StarlingXML(texture, i, data[i]);
|
||||
for (var i = 0; i < data.length; i++)
|
||||
{
|
||||
Parser.StarlingXML(texture, i, data[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Parser.StarlingXML(texture, 0, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Parser.StarlingXML(texture, 0, data);
|
||||
}
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
this.emit('addtexture', key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
@ -550,25 +674,30 @@ var TextureManager = new Class({
|
|||
* @param {HTMLImageElement} source - The source Image element.
|
||||
* @param {object} data - The Texture Atlas XML data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
addAtlasPyxel: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
var texture = null;
|
||||
|
||||
if (Array.isArray(data))
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
for (var i = 0; i < data.length; i++)
|
||||
texture = this.create(key, source);
|
||||
|
||||
if (Array.isArray(data))
|
||||
{
|
||||
Parser.Pyxel(texture, i, data[i]);
|
||||
for (var i = 0; i < data.length; i++)
|
||||
{
|
||||
Parser.Pyxel(texture, i, data[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Parser.Pyxel(texture, 0, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Parser.Pyxel(texture, 0, data);
|
||||
}
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
this.emit('addtexture', key, texture);
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
@ -584,15 +713,18 @@ var TextureManager = new Class({
|
|||
* @param {integer} width - The width of the Texture.
|
||||
* @param {integer} height - The height of the Texture.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
* @return {?Phaser.Textures.Texture} The Texture that was created, or `null` if the key is already in use.
|
||||
*/
|
||||
create: function (key, source, width, height)
|
||||
{
|
||||
var texture = new Texture(this, key, source, width, height);
|
||||
var texture = null;
|
||||
|
||||
this.list[key] = texture;
|
||||
if (this.checkKey(key))
|
||||
{
|
||||
texture = new Texture(this, key, source, width, height);
|
||||
|
||||
this.emit('addtexture', key, texture);
|
||||
this.list[key] = texture;
|
||||
}
|
||||
|
||||
return texture;
|
||||
},
|
||||
|
@ -816,6 +948,8 @@ var TextureManager = new Class({
|
|||
this.list = {};
|
||||
|
||||
this.game = null;
|
||||
|
||||
CanvasPool.remove(this._tempCanvas);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
*/
|
||||
|
||||
var CanvasPool = require('../display/canvas/CanvasPool');
|
||||
var Class = require('../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var IsSizePowerOfTwo = require('../math/pow2/IsSizePowerOfTwo');
|
||||
var ScaleModes = require('../renderer/ScaleModes');
|
||||
|
||||
|
@ -34,6 +34,15 @@ var TextureSource = new Class({
|
|||
{
|
||||
var game = texture.manager.game;
|
||||
|
||||
/**
|
||||
* The Texture this TextureSource belongs to.
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#renderer
|
||||
* @type {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)}
|
||||
* @since 3.6.1
|
||||
*/
|
||||
this.renderer = game.renderer;
|
||||
|
||||
/**
|
||||
* The Texture this TextureSource belongs to.
|
||||
*
|
||||
|
@ -143,9 +152,16 @@ var TextureSource = new Class({
|
|||
*/
|
||||
init: function (game)
|
||||
{
|
||||
if (game.config.renderType === CONST.WEBGL)
|
||||
if (this.renderer.gl)
|
||||
{
|
||||
this.glTexture = game.renderer.createTextureFromSource(this.image, this.width, this.height, this.scaleMode);
|
||||
if (this.isCanvas)
|
||||
{
|
||||
this.glTexture = this.renderer.canvasToTexture(this.image);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.glTexture = this.renderer.createTextureFromSource(this.image, this.width, this.height, this.scaleMode);
|
||||
}
|
||||
}
|
||||
|
||||
if (game.config.pixelArt)
|
||||
|
@ -168,24 +184,47 @@ var TextureSource = new Class({
|
|||
*/
|
||||
setFilter: function (filterMode)
|
||||
{
|
||||
var game = this.texture.manager.game;
|
||||
|
||||
if (game.config.renderType === CONST.WEBGL)
|
||||
if (this.renderer.gl)
|
||||
{
|
||||
game.renderer.setTextureFilter(this.glTexture, filterMode);
|
||||
this.renderer.setTextureFilter(this.glTexture, filterMode);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroys this Texture Source and nulls the source image reference.
|
||||
* If this TextureSource is backed by a Canvas and is running under WebGL,
|
||||
* it updates the WebGLTexture using the canvas data.
|
||||
*
|
||||
* @method Phaser.Textures.TextureSource#update
|
||||
* @since 3.6.1
|
||||
*/
|
||||
update: function ()
|
||||
{
|
||||
if (this.renderer.gl && this.isCanvas)
|
||||
{
|
||||
this.renderer.canvasToTexture(this.image, this.glTexture);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroys this Texture Source and nulls the references.
|
||||
*
|
||||
* @method Phaser.Textures.TextureSource#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.texture = null;
|
||||
if (this.glTexture)
|
||||
{
|
||||
this.renderer.deleteTexture(this.glTexture);
|
||||
}
|
||||
|
||||
if (this.isCanvas)
|
||||
{
|
||||
CanvasPool.remove(this.image);
|
||||
}
|
||||
|
||||
this.renderer = null;
|
||||
this.texture = null;
|
||||
this.image = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,67 @@ var CullTiles = function (layer, camera, outputArray)
|
|||
if (outputArray === undefined) { outputArray = []; }
|
||||
|
||||
outputArray.length = 0;
|
||||
|
||||
var zoom = camera.zoom;
|
||||
var originX = camera.width / 2;
|
||||
var originY = camera.height / 2;
|
||||
|
||||
camera.matrix.loadIdentity();
|
||||
camera.matrix.translate(camera.x + originX, camera.y + originY);
|
||||
camera.matrix.rotate(camera.rotation);
|
||||
camera.matrix.scale(zoom, zoom);
|
||||
camera.matrix.translate(-originX, -originY);
|
||||
camera.matrix.invert();
|
||||
|
||||
var tilemapLayer = layer.tilemapLayer;
|
||||
var tileW = layer.tileWidth;
|
||||
var tileH = layer.tileHeight;
|
||||
var cullX = ((camera.scrollX * tilemapLayer.scrollFactorX) - tileW);
|
||||
var cullY = ((camera.scrollY * tilemapLayer.scrollFactorY) - tileH);
|
||||
var cullW = (cullX + (camera.width + tileW * 2));
|
||||
var cullH = (cullY + (camera.height + tileH * 2));
|
||||
var mapData = layer.data;
|
||||
var mapWidth = layer.width;
|
||||
var mapHeight = layer.height;
|
||||
var cameraMatrix = camera.matrix.matrix;
|
||||
var a = cameraMatrix[0];
|
||||
var b = cameraMatrix[1];
|
||||
var c = cameraMatrix[2];
|
||||
var d = cameraMatrix[3];
|
||||
var e = cameraMatrix[4];
|
||||
var f = cameraMatrix[5];
|
||||
var tCullX = cullX * a + cullY * c + e;
|
||||
var tCullY = cullX * b + cullY * d + f;
|
||||
var tCullW = cullW * a + cullH * c + e;
|
||||
var tCullH = cullW * b + cullH * d + f;
|
||||
|
||||
|
||||
for (var y = 0; y < mapHeight; ++y)
|
||||
{
|
||||
for (var x = 0; x < mapWidth; ++x)
|
||||
{
|
||||
var tile = mapData[y][x];
|
||||
|
||||
if (tile === null || tile.index === -1)
|
||||
{ continue; }
|
||||
|
||||
var tileX = tile.pixelX * a + tile.pixelY * c + e;
|
||||
var tileY = tile.pixelX * b + tile.pixelY * d + f;
|
||||
|
||||
if (tile.visible &&
|
||||
tileX >= tCullX &&
|
||||
tileY >= tCullY &&
|
||||
tileX + tileW <= tCullW &&
|
||||
tileY + tileH <= tCullH
|
||||
)
|
||||
{
|
||||
outputArray.push(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* var tilemapLayer = layer.tilemapLayer;
|
||||
var mapData = layer.data;
|
||||
var mapWidth = layer.width;
|
||||
var mapHeight = layer.height;
|
||||
|
@ -55,7 +114,7 @@ var CullTiles = function (layer, camera, outputArray)
|
|||
outputArray.push(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
return outputArray;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue