mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 22:18:29 +00:00
Added jsdocs
This commit is contained in:
parent
7b04ea3130
commit
4c5150a24c
16 changed files with 1085 additions and 155 deletions
|
@ -1,6 +1,25 @@
|
|||
/**
|
||||
* @namespace Phaser.Textures.FilterMode
|
||||
*/
|
||||
|
||||
var CONST = {
|
||||
|
||||
/**
|
||||
* CSV Map Type
|
||||
*
|
||||
* @name Phaser.Textures.FilterMode.LINEAR
|
||||
* @type {number}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
LINEAR: 0,
|
||||
|
||||
/**
|
||||
* CSV Map Type
|
||||
*
|
||||
* @name Phaser.Textures.FilterMode.NEAREST
|
||||
* @type {number}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
NEAREST: 1
|
||||
|
||||
};
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
|
||||
var Class = require('../utils/Class');
|
||||
var Extend = require('../utils/object/Extend');
|
||||
|
||||
/**
|
||||
* A Frame is a section of a Texture.
|
||||
*/
|
||||
* @classdesc
|
||||
* A Frame is a section of a Texture.
|
||||
*
|
||||
* @class Frame
|
||||
* @memberOf Phaser.Textures
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture this Frame is a part of.
|
||||
* @param {integer|string} name - The name of this Frame. The name is unique within the Texture.
|
||||
* @param {integer} sourceIndex - The index of the TextureSource that this Frame is a part of.
|
||||
* @param {number} x - The x coordinate of the top-left of this Frame.
|
||||
* @param {number} y - The y coordinate of the top-left of this Frame.
|
||||
* @param {number} width - The width of this Frame.
|
||||
* @param {number} height - The height of this Frame.
|
||||
*/
|
||||
var Frame = new Class({
|
||||
|
||||
initialize:
|
||||
|
@ -12,106 +25,219 @@ var Frame = new Class({
|
|||
function Frame (texture, name, sourceIndex, x, y, width, height)
|
||||
{
|
||||
/**
|
||||
* @property {Phaser.Texture} texture - The Texture this frame belongs to.
|
||||
*/
|
||||
* The Texture this Frame is a part of.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#texture
|
||||
* @type {Phaser.Textures.Texture}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.texture = texture;
|
||||
|
||||
/**
|
||||
* @property {string} name - The name of this frame within the Texture.
|
||||
*/
|
||||
* The name of this Frame.
|
||||
* The name is unique within the Texture.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#name
|
||||
* @type {string}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* The TextureSource this Frame is part of.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#source
|
||||
* @type {Phaser.Textures.TextureSource}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.source = texture.source[sourceIndex];
|
||||
|
||||
/**
|
||||
* The index of the TextureSource in the Texture sources array.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#sourceIndex
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.sourceIndex = sourceIndex;
|
||||
|
||||
/**
|
||||
* @property {number} cutX - X position within the source image to cut from.
|
||||
*/
|
||||
* X position within the source image to cut from.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#cutX
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.cutX = x;
|
||||
|
||||
/**
|
||||
* @property {number} cutY - Y position within the source image to cut from.
|
||||
*/
|
||||
* Y position within the source image to cut from.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#cutY
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.cutY = y;
|
||||
|
||||
/**
|
||||
* @property {number} cutWidth - The width of the area in the source image to cut.
|
||||
*/
|
||||
* The width of the area in the source image to cut.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#cutWidth
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.cutWidth = width;
|
||||
|
||||
/**
|
||||
* @property {number} cutHeight - The height of the area in the source image to cut.
|
||||
*/
|
||||
* The height of the area in the source image to cut.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#cutHeight
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.cutHeight = height;
|
||||
|
||||
/**
|
||||
* @property {number} x - The X rendering offset of this Frame, taking trim into account.
|
||||
*/
|
||||
* The X rendering offset of this Frame, taking trim into account.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#x
|
||||
* @type {integer}
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.x = 0;
|
||||
|
||||
/**
|
||||
* @property {number} y - The Y rendering offset of this Frame, taking trim into account.
|
||||
*/
|
||||
* The Y rendering offset of this Frame, taking trim into account.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#y
|
||||
* @type {integer}
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.y = 0;
|
||||
|
||||
/**
|
||||
* @property {number} width - The rendering width of this Frame, taking trim into account.
|
||||
*/
|
||||
* The rendering width of this Frame, taking trim into account.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#width
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.width = width;
|
||||
|
||||
/**
|
||||
* @property {number} height - The rendering height of this Frame, taking trim into account.
|
||||
*/
|
||||
* The rendering height of this Frame, taking trim into account.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#height
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.height = height;
|
||||
|
||||
// The half sizes of this frame (to save in constant calculations in the renderer)
|
||||
/**
|
||||
* Half the width, floored.
|
||||
* Precalculated for the renderer.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#halfWidth
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.halfWidth = Math.floor(width * 0.5);
|
||||
|
||||
|
||||
/**
|
||||
* Half the height, floored.
|
||||
* Precalculated for the renderer.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#halfHeight
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.halfHeight = Math.floor(height * 0.5);
|
||||
|
||||
/**
|
||||
* @property {number} width - The rendering width of this Frame, taking trim into account.
|
||||
*/
|
||||
* The x center of this frame, floored.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#centerX
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.centerX = Math.floor(width / 2);
|
||||
|
||||
/**
|
||||
* @property {number} height - The rendering height of this Frame, taking trim into account.
|
||||
*/
|
||||
* The y center of this frame, floored.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#centerY
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.centerY = Math.floor(height / 2);
|
||||
|
||||
/**
|
||||
* @property {number} pivotX - The horizontal pivot point of this Frame.
|
||||
*/
|
||||
* The horizontal pivot point of this Frame.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#pivotX
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.pivotX = 0;
|
||||
|
||||
/**
|
||||
* @property {number} height - The vertical pivot point of this Frame.
|
||||
*/
|
||||
* The vertical pivot point of this Frame.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#pivotY
|
||||
* @type {number}
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.pivotY = 0;
|
||||
|
||||
/**
|
||||
* Is this frame is rotated or not in the Texture?
|
||||
* Rotation allows you to use rotated frames in texture atlas packing.
|
||||
* It has nothing to do with Sprite rotation.
|
||||
*
|
||||
* @property {boolean} rotated
|
||||
* @default
|
||||
*/
|
||||
* **CURRENTLY UNSUPPORTED**
|
||||
*
|
||||
* Is this frame is rotated or not in the Texture?
|
||||
* Rotation allows you to use rotated frames in texture atlas packing.
|
||||
* It has nothing to do with Sprite rotation.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#rotated
|
||||
* @type {boolean}
|
||||
* @default false
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.rotated = false;
|
||||
|
||||
// Over-rides the Renderer setting? -1 = use Renderer Setting, 0 = No rounding, 1 = Round
|
||||
/**
|
||||
* Over-rides the Renderer setting.
|
||||
* -1 = use Renderer Setting
|
||||
* 0 = No rounding
|
||||
* 1 = Round
|
||||
*
|
||||
* @name Phaser.Textures.Frame#autoRound
|
||||
* @type {integer}
|
||||
* @default -1
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.autoRound = -1;
|
||||
|
||||
// Any Frame specific custom data can be stored here
|
||||
/**
|
||||
* Any Frame specific custom data can be stored here.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#customData
|
||||
* @type {object}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.customData = {};
|
||||
|
||||
/**
|
||||
* The un-modified source frame, trim and UV data.
|
||||
*
|
||||
* @private
|
||||
* @property {object} data
|
||||
*/
|
||||
* The un-modified source frame, trim and UV data.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#data
|
||||
* @type {object}
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.data = {
|
||||
cut: {
|
||||
x: x,
|
||||
|
@ -157,16 +283,20 @@ var Frame = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* If the frame was trimmed when added to the Texture Atlas, this records the trim and source data.
|
||||
*
|
||||
* @method Phaser.TextureFrame#setTrim
|
||||
* @param {number} actualWidth - The width of the frame before being trimmed.
|
||||
* @param {number} actualHeight - The height of the frame before being trimmed.
|
||||
* @param {number} destX - The destination X position of the trimmed frame for display.
|
||||
* @param {number} destY - The destination Y position of the trimmed frame for display.
|
||||
* @param {number} destWidth - The destination width of the trimmed frame for display.
|
||||
* @param {number} destHeight - The destination height of the trimmed frame for display.
|
||||
*/
|
||||
* If the frame was trimmed when added to the Texture Atlas, this records the trim and source data.
|
||||
*
|
||||
* @method Phaser.Textures.Frame#setTrim
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {number} actualWidth - The width of the frame before being trimmed.
|
||||
* @param {number} actualHeight - The height of the frame before being trimmed.
|
||||
* @param {number} destX - The destination X position of the trimmed frame for display.
|
||||
* @param {number} destY - The destination Y position of the trimmed frame for display.
|
||||
* @param {number} destWidth - The destination width of the trimmed frame for display.
|
||||
* @param {number} destHeight - The destination height of the trimmed frame for display.
|
||||
*
|
||||
* @return {Phaser.Textures.Frame} This Frame object.
|
||||
*/
|
||||
setTrim: function (actualWidth, actualHeight, destX, destY, destWidth, destHeight)
|
||||
{
|
||||
var data = this.data;
|
||||
|
@ -201,11 +331,13 @@ var Frame = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Updates the internal WebGL UV cache and the drawImage cache.
|
||||
*
|
||||
* @method updateUVs
|
||||
* @private
|
||||
*/
|
||||
* Updates the internal WebGL UV cache and the drawImage cache.
|
||||
*
|
||||
* @method Phaser.Textures.Frame#updateUVs
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.Textures.Frame} This Frame object.
|
||||
*/
|
||||
updateUVs: function ()
|
||||
{
|
||||
var cx = this.cutX;
|
||||
|
@ -244,11 +376,13 @@ var Frame = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Updates the internal WebGL UV cache.
|
||||
*
|
||||
* @method updateUVsInverted
|
||||
* @private
|
||||
*/
|
||||
* Updates the internal WebGL UV cache.
|
||||
*
|
||||
* @method Phaser.Textures.Frame#updateUVsInverted
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.Textures.Frame} This Frame object.
|
||||
*/
|
||||
updateUVsInverted: function ()
|
||||
{
|
||||
var tw = this.source.width;
|
||||
|
@ -270,6 +404,14 @@ var Frame = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clones this Frame into a new Frame object.
|
||||
*
|
||||
* @method Phaser.Textures.Frame#clone
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {Phaser.Textures.Frame} A clone of this Frame.
|
||||
*/
|
||||
clone: function ()
|
||||
{
|
||||
var clone = new Frame(this.texture, this.name, this.sourceIndex);
|
||||
|
@ -300,6 +442,12 @@ var Frame = new Class({
|
|||
return clone;
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroys this Frames references.
|
||||
*
|
||||
* @method Phaser.Textures.Frame#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.texture = null;
|
||||
|
@ -308,12 +456,14 @@ var Frame = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* The width of the Frame in its un-trimmed, un-padded state, as prepared in the art package,
|
||||
* before being packed.
|
||||
*
|
||||
* @name Phaser.TextureFrame#realWidth
|
||||
* @property {any} realWidth
|
||||
*/
|
||||
* The width of the Frame in its un-trimmed, un-padded state, as prepared in the art package,
|
||||
* before being packed.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#realWidth
|
||||
* @type {number}
|
||||
* @readOnly
|
||||
* @since 3.0.0
|
||||
*/
|
||||
realWidth: {
|
||||
|
||||
get: function ()
|
||||
|
@ -324,12 +474,14 @@ var Frame = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* The height of the Frame in its un-trimmed, un-padded state, as prepared in the art package,
|
||||
* before being packed.
|
||||
*
|
||||
* @name Phaser.TextureFrame#realHeight
|
||||
* @property {any} realHeight
|
||||
*/
|
||||
* The height of the Frame in its un-trimmed, un-padded state, as prepared in the art package,
|
||||
* before being packed.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#realHeight
|
||||
* @type {number}
|
||||
* @readOnly
|
||||
* @since 3.0.0
|
||||
*/
|
||||
realHeight: {
|
||||
|
||||
get: function ()
|
||||
|
@ -340,11 +492,13 @@ var Frame = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* UVs
|
||||
*
|
||||
* @name Phaser.TextureFrame#uvs
|
||||
* @property {Object} uvs
|
||||
*/
|
||||
* The UV data for this Frame.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#uvs
|
||||
* @type {object}
|
||||
* @readOnly
|
||||
* @since 3.0.0
|
||||
*/
|
||||
uvs: {
|
||||
|
||||
get: function ()
|
||||
|
@ -355,10 +509,13 @@ var Frame = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* The radius of the Frame (derived from sqrt(w * w + h * h) / 2)
|
||||
* @name Phaser.TextureFrame#radius
|
||||
* @property {number} radius
|
||||
*/
|
||||
* The radius of the Frame (derived from sqrt(w * w + h * h) / 2)
|
||||
*
|
||||
* @name Phaser.Textures.Frame#radius
|
||||
* @type {number}
|
||||
* @readOnly
|
||||
* @since 3.0.0
|
||||
*/
|
||||
radius: {
|
||||
|
||||
get: function ()
|
||||
|
@ -369,10 +526,13 @@ var Frame = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Is the Frame trimmed?
|
||||
* @name Phaser.TextureFrame#trimmed
|
||||
* @property {boolean} trimmed
|
||||
*/
|
||||
* Is the Frame trimmed or not?
|
||||
*
|
||||
* @name Phaser.Textures.Frame#trimmed
|
||||
* @type {boolean}
|
||||
* @readOnly
|
||||
* @since 3.0.0
|
||||
*/
|
||||
trimmed: {
|
||||
|
||||
get: function ()
|
||||
|
@ -383,11 +543,13 @@ var Frame = new Class({
|
|||
},
|
||||
|
||||
/**
|
||||
* Canvas Draw Image data
|
||||
*
|
||||
* @name Phaser.TextureFrame#canvasData
|
||||
* @property {Object} canvasData
|
||||
*/
|
||||
* The Canvas drawImage data object.
|
||||
*
|
||||
* @name Phaser.Textures.Frame#canvasData
|
||||
* @type {object}
|
||||
* @readOnly
|
||||
* @since 3.0.0
|
||||
*/
|
||||
canvasData: {
|
||||
|
||||
get: function ()
|
||||
|
|
|
@ -3,46 +3,113 @@ var Frame = require('./Frame');
|
|||
var TextureSource = require('./TextureSource');
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* Textures are managed by the global TextureManager. This is a singleton class that is
|
||||
* responsible for creating and delivering Textures and their corresponding Frames to Game Objects.
|
||||
*
|
||||
* Sprites and other Game Objects get the texture data they need from the TextureManager.
|
||||
*/
|
||||
* @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
|
||||
* 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.
|
||||
*
|
||||
* Textures are managed by the global TextureManager. This is a singleton class that is
|
||||
* responsible for creating and delivering Textures and their corresponding Frames to Game Objects.
|
||||
*
|
||||
* Sprites and other Game Objects get the texture data they need from the TextureManager.
|
||||
*
|
||||
* @class Texture
|
||||
* @memberOf Phaser.Textures
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @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 {Image|HTMLCanvasElement} source - The source that is used to create the texture. Usually an Image, but can also be a Canvas.
|
||||
* @param {number} [width] - The width of the Texture. This is optional and automatically derived from the source images.
|
||||
* @param {number} [height] - The height of the Texture. This is optional and automatically derived from the source images.
|
||||
*/
|
||||
var Texture = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function Texture (manager, key, source, width, height)
|
||||
{
|
||||
this.manager = manager;
|
||||
|
||||
if (!Array.isArray(source))
|
||||
{
|
||||
source = [ source ];
|
||||
}
|
||||
|
||||
/**
|
||||
* A reference to the Texture Manager this Texture belongs to.
|
||||
*
|
||||
* @name Phaser.Textures.Texture#manager
|
||||
* @type {Phaser.Textures.TextureManager}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.manager = manager;
|
||||
|
||||
/**
|
||||
* The unique string-based key of this Texture.
|
||||
*
|
||||
* @name Phaser.Textures.Texture#key
|
||||
* @type {string}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
/**
|
||||
* The source that is used to create the texture.
|
||||
* Usually an Image, but can also be a Canvas.
|
||||
*/
|
||||
* An array of TextureSource instances.
|
||||
* These are unique to this Texture and contain the actual Image (or Canvas) data.
|
||||
*
|
||||
* @name Phaser.Textures.Texture#source
|
||||
* @type {Phaser.Textures.TextureSource[]}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.source = [];
|
||||
|
||||
/**
|
||||
* An array of TextureSource data instances.
|
||||
* Used to store additional data images, such as normal maps or specular maps.
|
||||
*
|
||||
* @name Phaser.Textures.Texture#dataSource
|
||||
* @type {array}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.dataSource = [];
|
||||
|
||||
/**
|
||||
* A key-value object pair associating the unique Frame keys with the Frames objects.
|
||||
*
|
||||
* @name Phaser.Textures.Texture#frames
|
||||
* @type {object}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.frames = {};
|
||||
|
||||
// Any additional data that was set in the source JSON (if any), or any extra data you'd like to store relating to this texture
|
||||
/**
|
||||
* Any additional data that was set in the source JSON (if any),
|
||||
* or any extra data you'd like to store relating to this texture
|
||||
*
|
||||
* @name Phaser.Textures.Texture#customData
|
||||
* @type {object}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.customData = {};
|
||||
|
||||
/**
|
||||
* The name of the first frame of the Texture.
|
||||
*
|
||||
* @name Phaser.Textures.Texture#firstFrame
|
||||
* @type {string}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.firstFrame = '__BASE';
|
||||
|
||||
/**
|
||||
* The total number of Frames in this Texture.
|
||||
*
|
||||
* @name Phaser.Textures.Texture#frameTotal
|
||||
* @type {integer}
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.frameTotal = 0;
|
||||
|
||||
// Load the Sources
|
||||
|
@ -52,6 +119,23 @@ var Texture = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a new Frame to this Texture.
|
||||
*
|
||||
* A Frame is a rectangular region of a TextureSource with a unique index or string-based key.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#add
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer|string} name - The name of this Frame. The name is unique within the Texture.
|
||||
* @param {integer} sourceIndex - The index of the TextureSource that this Frame is a part of.
|
||||
* @param {number} x - The x coordinate of the top-left of this Frame.
|
||||
* @param {number} y - The y coordinate of the top-left of this Frame.
|
||||
* @param {number} width - The width of this Frame.
|
||||
* @param {number} height - The height of this Frame.
|
||||
*
|
||||
* @return {Phaser.Textures.Frame} The Frame that was added to this Texture.
|
||||
*/
|
||||
add: function (name, sourceIndex, x, y, width, height)
|
||||
{
|
||||
var frame = new Frame(this, name, sourceIndex, x, y, width, height);
|
||||
|
@ -72,11 +156,35 @@ var Texture = new Class({
|
|||
return frame;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks to see if a Frame matching the given key exists within this Texture.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#has
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string} name - The key of the Frame to check for.
|
||||
*
|
||||
* @return {boolean} True if a Frame with the matching key exists in this Texture.
|
||||
*/
|
||||
has: function (name)
|
||||
{
|
||||
return (this.frames[name]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets a Frame from this Texture based on either the key or the index of the Frame.
|
||||
*
|
||||
* In a Texture Atlas Frames are typically referenced by a key.
|
||||
* In a Sprite Sheet Frames are referenced by an index.
|
||||
* Passing no value for the name returns the base texture.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#get
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string|integer} [name] - The string-based name, or integer based index, of the Frame to get from this Texture.
|
||||
*
|
||||
* @return {Phaser.Textures.Frame} The Texture Frame.
|
||||
*/
|
||||
get: function (name)
|
||||
{
|
||||
if (name === undefined || name === null || (typeof name !== 'string' && typeof name !== 'number'))
|
||||
|
@ -98,6 +206,19 @@ var Texture = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Takes the given TextureSource and returns the index of it within this Texture.
|
||||
* If it's not in this Texture, it returns -1.
|
||||
* Unless this Texture has multiple TextureSources, such as with a multi-atlas, this
|
||||
* method will always return zero or -1.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#getTextureSourceIndex
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.TextureSource} source - The TextureSource to check.
|
||||
*
|
||||
* @return {integer} The index of the TextureSource within this Texture, or -1 if not in this Texture.
|
||||
*/
|
||||
getTextureSourceIndex: function (source)
|
||||
{
|
||||
for (var i = 0; i < this.source.length; i++)
|
||||
|
@ -111,7 +232,16 @@ var Texture = new Class({
|
|||
return -1;
|
||||
},
|
||||
|
||||
// source = TextureSource object
|
||||
/**
|
||||
* Returns an array of all the Frames in the given TextureSource.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#getFramesFromTextureSource
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {integer} sourceIndex - The index of the TextureSource to get the Frames from.
|
||||
*
|
||||
* @return {Phaser.Textures.Frame[]} An array of Texture Frames.
|
||||
*/
|
||||
getFramesFromTextureSource: function (sourceIndex)
|
||||
{
|
||||
var out = [];
|
||||
|
@ -134,6 +264,19 @@ var Texture = new Class({
|
|||
return out;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns an array with all of the names of the Frames in this Texture.
|
||||
*
|
||||
* Useful if you want to randomly assign a Frame to a Game Object, as you can
|
||||
* pick a random element from the returned array.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#getFrameNames
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {boolean} [includeBase=false] - Include the `__BASE` Frame in the output array?
|
||||
*
|
||||
* @return {string[]} An array of all Frame names in this Texture.
|
||||
*/
|
||||
getFrameNames: function (includeBase)
|
||||
{
|
||||
if (includeBase === undefined) { includeBase = false; }
|
||||
|
@ -153,6 +296,18 @@ var Texture = new Class({
|
|||
return out;
|
||||
},
|
||||
|
||||
/**
|
||||
* Given a Frame name, return the source image it uses to render with.
|
||||
*
|
||||
* This will return the actual DOM Image or Canvas element.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#getSourceImage
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string|integer} [name] - The string-based name, or integer based index, of the Frame to get from this Texture.
|
||||
*
|
||||
* @return {Image|HTMLCanvasElement} The DOM Image or Canvas Element.
|
||||
*/
|
||||
getSourceImage: function (name)
|
||||
{
|
||||
if (name === undefined || name === null || this.frameTotal === 1)
|
||||
|
@ -174,6 +329,17 @@ var Texture = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a data source image to this Texture.
|
||||
*
|
||||
* An example of a data source image would be a normal map, where all of the Frames for this Texture
|
||||
* equally apply to the normal map.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#setDataSource
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Image|HTMLCanvasElement} data - The source image.
|
||||
*/
|
||||
setDataSource: function (data)
|
||||
{
|
||||
if (!Array.isArray(data))
|
||||
|
@ -189,6 +355,20 @@ var Texture = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the Filter Mode for this Texture.
|
||||
*
|
||||
* The mode can be either Linear, the default, or Nearest.
|
||||
*
|
||||
* For pixel-art you should use Nearest.
|
||||
*
|
||||
* The mode applies to the entire Texture, not just a specific Frame of it.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#setFilter
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.FilterMode.LINEAR|Phaser.Textures.FilterMode.NEAREST} filterMode - The Filter Mode.
|
||||
*/
|
||||
setFilter: function (filterMode)
|
||||
{
|
||||
var i;
|
||||
|
@ -204,6 +384,12 @@ var Texture = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroys this Texture and releases references to its sources and frames.
|
||||
*
|
||||
* @method Phaser.Textures.Texture#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
var i;
|
||||
|
|
|
@ -8,13 +8,22 @@ var Parser = require('./parsers');
|
|||
var Texture = require('./Texture');
|
||||
|
||||
/**
|
||||
* Textures are managed by the global TextureManager. This is a singleton class that is
|
||||
* responsible for creating and delivering Textures and their corresponding Frames to Game Objects.
|
||||
*
|
||||
* Sprites and other Game Objects get the texture data they need from the TextureManager.
|
||||
*
|
||||
* Access it via `scene.textures`.
|
||||
*/
|
||||
* @classdesc
|
||||
* Textures are managed by the global TextureManager. This is a singleton class that is
|
||||
* responsible for creating and delivering Textures and their corresponding Frames to Game Objects.
|
||||
*
|
||||
* Sprites and other Game Objects get the texture data they need from the TextureManager.
|
||||
*
|
||||
* Access it via `scene.textures`.
|
||||
*
|
||||
* @class TextureManager
|
||||
* @extends Phaser.Textures.EventEmitter
|
||||
* @memberOf Phaser.Textures
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Game} game - [description]
|
||||
*/
|
||||
var TextureManager = new Class({
|
||||
|
||||
Extends: EventEmitter,
|
||||
|
@ -25,20 +34,74 @@ var TextureManager = new Class({
|
|||
{
|
||||
EventEmitter.call(this);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#game
|
||||
* @type {Phaser.Game}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#name
|
||||
* @type {string}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.name = 'TextureManager';
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#list
|
||||
* @type {object}
|
||||
* @default {}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.list = {};
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#_tempCanvas
|
||||
* @type {HTMLCanvasElement}
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._tempCanvas = CanvasPool.create2D(this, 1, 1);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#_tempContext
|
||||
* @type {CanvasRenderingContext2D}
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._tempContext = this._tempCanvas.getContext('2d');
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @name Phaser.Textures.TextureManager#_pending
|
||||
* @type {integer}
|
||||
* @private
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._pending = 0;
|
||||
|
||||
game.events.once('boot', this.boot, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#boot
|
||||
* @since 3.0.0
|
||||
*/
|
||||
boot: function ()
|
||||
{
|
||||
this._pending = 2;
|
||||
|
@ -52,6 +115,12 @@ var TextureManager = new Class({
|
|||
this.game.events.once('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#updatePending
|
||||
* @since 3.0.0
|
||||
*/
|
||||
updatePending: function ()
|
||||
{
|
||||
this._pending--;
|
||||
|
@ -65,6 +134,15 @@ var TextureManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a new Texture to the Texture Manager created from the given Base64 encoded data.
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addBase64
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string} key - The unique string-based key of the Texture.
|
||||
* @param {any} data - The Base64 encoded data.
|
||||
*/
|
||||
addBase64: function (key, data)
|
||||
{
|
||||
var _this = this;
|
||||
|
@ -88,6 +166,18 @@ var TextureManager = new Class({
|
|||
image.src = data;
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a new Texture to the Texture Manager created from the given Image element.
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addImage
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {string} key - The unique string-based key of the Texture.
|
||||
* @param {Image} source - The source Image element.
|
||||
* @param {Image} [dataSource] - An optional data Image element.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture that was created.
|
||||
*/
|
||||
addImage: function (key, source, dataSource)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
|
@ -102,6 +192,17 @@ var TextureManager = new Class({
|
|||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#generate
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} config - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
generate: function (key, config)
|
||||
{
|
||||
var canvas = CanvasPool.create(this, 1, 1);
|
||||
|
@ -113,6 +214,18 @@ var TextureManager = new Class({
|
|||
return this.addCanvas(key, canvas);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#createCanvas
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} width - [description]
|
||||
* @param {[type]} height - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
createCanvas: function (key, width, height)
|
||||
{
|
||||
if (width === undefined) { width = 256; }
|
||||
|
@ -123,6 +236,17 @@ var TextureManager = new Class({
|
|||
return this.addCanvas(key, canvas);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addCanvas
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} source - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addCanvas: function (key, source)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
|
@ -132,6 +256,18 @@ var TextureManager = new Class({
|
|||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addAtlas
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} source - [description]
|
||||
* @param {[type]} data - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addAtlas: function (key, source, data)
|
||||
{
|
||||
// Is it a Hash or an Array?
|
||||
|
@ -146,6 +282,18 @@ var TextureManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addAtlasJSONArray
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} source - [description]
|
||||
* @param {[type]} data - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addAtlasJSONArray: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
|
@ -165,6 +313,18 @@ var TextureManager = new Class({
|
|||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addAtlasJSONHash
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} source - [description]
|
||||
* @param {[type]} data - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addAtlasJSONHash: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
|
@ -184,6 +344,18 @@ var TextureManager = new Class({
|
|||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addUnityAtlas
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} source - [description]
|
||||
* @param {[type]} data - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addUnityAtlas: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
|
@ -205,6 +377,18 @@ var TextureManager = new Class({
|
|||
* @param {number} [config.margin=0] - If the frames have been drawn with a margin, specify the amount here.
|
||||
* @param {number} [config.spacing=0] - If the frames have been drawn with spacing between them, specify the amount here.
|
||||
*/
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addSpriteSheet
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} source - [description]
|
||||
* @param {[type]} config - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addSpriteSheet: function (key, source, config)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
|
@ -217,6 +401,17 @@ var TextureManager = new Class({
|
|||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addSpriteSheetFromAtlas
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} config - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addSpriteSheetFromAtlas: function (key, config)
|
||||
{
|
||||
var atlasKey = GetValue(config, 'atlas', null);
|
||||
|
@ -248,6 +443,18 @@ var TextureManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addAtlasStarlingXML
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} source - [description]
|
||||
* @param {[type]} data - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addAtlasStarlingXML: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
|
@ -267,6 +474,18 @@ var TextureManager = new Class({
|
|||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#addAtlasPyxel
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} source - [description]
|
||||
* @param {[type]} data - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addAtlasPyxel: function (key, source, data)
|
||||
{
|
||||
var texture = this.create(key, source);
|
||||
|
@ -286,6 +505,19 @@ var TextureManager = new Class({
|
|||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#create
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} source - [description]
|
||||
* @param {[type]} width - [description]
|
||||
* @param {[type]} height - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
create: function (key, source, width, height)
|
||||
{
|
||||
var texture = new Texture(this, key, source, width, height);
|
||||
|
@ -295,11 +527,31 @@ var TextureManager = new Class({
|
|||
return texture;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#exists
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
exists: function (key)
|
||||
{
|
||||
return (this.list.hasOwnProperty(key));
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#get
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
get: function (key)
|
||||
{
|
||||
if (key === undefined) { key = '__DEFAULT'; }
|
||||
|
@ -314,6 +566,17 @@ var TextureManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#cloneFrame
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} frame - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
cloneFrame: function (key, frame)
|
||||
{
|
||||
if (this.list[key])
|
||||
|
@ -322,6 +585,17 @@ var TextureManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#getFrame
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} frame - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
getFrame: function (key, frame)
|
||||
{
|
||||
if (this.list[key])
|
||||
|
@ -330,6 +604,14 @@ var TextureManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#getTextureKeys
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
getTextureKeys: function ()
|
||||
{
|
||||
var output = [];
|
||||
|
@ -345,6 +627,19 @@ var TextureManager = new Class({
|
|||
return output;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#getPixel
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} x - [description]
|
||||
* @param {[type]} y - [description]
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} frame - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
getPixel: function (x, y, key, frame)
|
||||
{
|
||||
var textureFrame = this.getFrame(key, frame);
|
||||
|
@ -378,6 +673,18 @@ var TextureManager = new Class({
|
|||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#setTexture
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObject - [description]
|
||||
* @param {[type]} key - [description]
|
||||
* @param {[type]} frame - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setTexture: function (gameObject, key, frame)
|
||||
{
|
||||
if (this.list[key])
|
||||
|
@ -397,6 +704,15 @@ var TextureManager = new Class({
|
|||
* @param {object} [thisArg] - Value to use as `this` when executing callback.
|
||||
* @param {...*} [arguments] - Additional arguments that will be passed to the callback, after the child.
|
||||
*/
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#each
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} callback - [description]
|
||||
* @param {[type]} thisArg - [description]
|
||||
*/
|
||||
each: function (callback, thisArg)
|
||||
{
|
||||
var args = [ null ];
|
||||
|
@ -414,6 +730,12 @@ var TextureManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Textures.TextureManager#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
for (var texture in this.list)
|
||||
|
|
|
@ -3,6 +3,23 @@ var CONST = require('../const');
|
|||
var IsSizePowerOfTwo = require('../math/pow2/IsSizePowerOfTwo');
|
||||
var ScaleModes = require('../renderer/ScaleModes');
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A Texture Source is the encapsulation of the actual source data for a Texture.
|
||||
* This is typically an Image Element, loaded from the file system or network, or a Canvas Element.
|
||||
*
|
||||
* A Texture can contain multiple Texture Sources, which only happens when a multi-atlas is loaded.
|
||||
*
|
||||
* @class TextureSource
|
||||
* @memberOf Phaser.Textures
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture this TextureSource belongs to.
|
||||
* @param {Image|HTMLCanvasElement} source - The source image data.
|
||||
* @param {integer} [width] - Optional width of the source image. If not given it's derived from the source itself.
|
||||
* @param {integer} [height] - Optional height of the source image. If not given it's derived from the source itself.
|
||||
*/
|
||||
var TextureSource = new Class({
|
||||
|
||||
initialize:
|
||||
|
@ -11,29 +28,113 @@ var TextureSource = new Class({
|
|||
{
|
||||
var game = texture.manager.game;
|
||||
|
||||
/**
|
||||
* The Texture this TextureSource belongs to.
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#texture
|
||||
* @type {string}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.texture = texture;
|
||||
|
||||
/**
|
||||
* The source image data. This is either an Image Element, or a Canvas Element.
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#image
|
||||
* @type {Image|HTMLCanvasElement}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.image = source;
|
||||
|
||||
/**
|
||||
* Currently un-used.
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#compressionAlgorithm
|
||||
* @type {integer}
|
||||
* @default null
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.compressionAlgorithm = null;
|
||||
|
||||
/**
|
||||
* The resolution of the source image.
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#resolution
|
||||
* @type {number}
|
||||
* @default 1
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.resolution = 1;
|
||||
|
||||
|
||||
/**
|
||||
* The width of the source image. If not specified in the constructor it will check
|
||||
* the `naturalWidth` and then `width` properties of the source image.
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#width
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.width = width || source.naturalWidth || source.width || 0;
|
||||
|
||||
/**
|
||||
* The height of the source image. If not specified in the constructor it will check
|
||||
* the `naturalHeight` and then `height` properties of the source image.
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#height
|
||||
* @type {integer}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.height = height || source.naturalHeight || source.height || 0;
|
||||
|
||||
/**
|
||||
* The Scale Mode the image will use when rendering.
|
||||
* Either Linear or Nearest.
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#scaleMode
|
||||
* @type {[type]}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.scaleMode = ScaleModes.DEFAULT;
|
||||
|
||||
/**
|
||||
* Is the source image a Canvas Element?
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#isCanvas
|
||||
* @type {boolean}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.isCanvas = (source instanceof HTMLCanvasElement);
|
||||
|
||||
/**
|
||||
* Are the source image dimensions a power of two?
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#isPowerOf2
|
||||
* @type {boolean}
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.isPowerOf2 = IsSizePowerOfTwo(this.width, this.height);
|
||||
|
||||
/**
|
||||
* The WebGL Texture of the source image.
|
||||
*
|
||||
* @name Phaser.Textures.TextureSource#glTexture
|
||||
* @type {?[type]}
|
||||
* @default null
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.glTexture = null;
|
||||
|
||||
this.init(game);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a WebGL Texture, if required, and sets the Texture filter mode.
|
||||
*
|
||||
* @method Phaser.Textures.TextureSource#init
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Game} game - A reference to the Phaser Game instance.
|
||||
*/
|
||||
init: function (game)
|
||||
{
|
||||
if (game.config.renderType === CONST.WEBGL)
|
||||
|
@ -47,6 +148,18 @@ var TextureSource = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the Filter Mode for this Texture.
|
||||
*
|
||||
* The mode can be either Linear, the default, or Nearest.
|
||||
*
|
||||
* For pixel-art you should use Nearest.
|
||||
*
|
||||
* @method Phaser.Textures.TextureSource#setFilter
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.FilterMode.LINEAR|Phaser.Textures.FilterMode.NEAREST} filterMode - The Filter Mode.
|
||||
*/
|
||||
setFilter: function (filterMode)
|
||||
{
|
||||
var game = this.texture.manager.game;
|
||||
|
@ -57,6 +170,12 @@ var TextureSource = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroys this Texture Source and nulls the source image reference.
|
||||
*
|
||||
* @method Phaser.Textures.TextureSource#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.texture = null;
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
module.exports = {
|
||||
|
||||
Parsers: require('./parsers/'),
|
||||
|
||||
FilterMode: require('./FilterMode'),
|
||||
Frame: require('./Frame'),
|
||||
Texture: require('./Texture'),
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/**
|
||||
* Adds a Canvas Element to a Texture.
|
||||
*
|
||||
* @function Phaser.Textures.Parsers.Canvas
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
|
||||
* @param {integer} sourceIndex - The index of the TextureSource.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
|
||||
*/
|
||||
var Canvas = function (texture, sourceIndex)
|
||||
{
|
||||
var source = texture.source[sourceIndex];
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/**
|
||||
* Adds an Image Element to a Texture.
|
||||
*
|
||||
* @function Phaser.Textures.Parsers.Image
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
|
||||
* @param {integer} sourceIndex - The index of the TextureSource.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
|
||||
*/
|
||||
var Image = function (texture, sourceIndex)
|
||||
{
|
||||
var source = texture.source[sourceIndex];
|
||||
|
|
|
@ -1,5 +1,18 @@
|
|||
var Clone = require('../../utils/object/Clone');
|
||||
|
||||
/**
|
||||
* Parses a Texture Atlas JSON Array and adds the Frames to the Texture.
|
||||
* JSON format expected to match that defined by Texture Packer, with the frames property containing an array of Frames.
|
||||
*
|
||||
* @function Phaser.Textures.Parsers.JSONArray
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
|
||||
* @param {integer} sourceIndex - The index of the TextureSource.
|
||||
* @param {object} json - The JSON data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
|
||||
*/
|
||||
var JSONArray = function (texture, sourceIndex, json)
|
||||
{
|
||||
// Malformed?
|
||||
|
|
|
@ -1,5 +1,18 @@
|
|||
var Clone = require('../../utils/object/Clone');
|
||||
|
||||
/**
|
||||
* Parses a Texture Atlas JSON Hash and adds the Frames to the Texture.
|
||||
* JSON format expected to match that defined by Texture Packer, with the frames property containing an object of Frames.
|
||||
*
|
||||
* @function Phaser.Textures.Parsers.JSONHash
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
|
||||
* @param {integer} sourceIndex - The index of the TextureSource.
|
||||
* @param {object} json - The JSON data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
|
||||
*/
|
||||
var JSONHash = function (texture, sourceIndex, json)
|
||||
{
|
||||
// Malformed?
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/**
|
||||
* Parses a Pyxel JSON object and adds the Frames to a Texture.
|
||||
*
|
||||
* @function Phaser.Textures.Parsers.Pyxel
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
|
||||
* @param {object} json - The JSON data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
|
||||
*/
|
||||
var Pyxel = function (texture, json)
|
||||
{
|
||||
// Malformed? There are a few keys to check here.
|
||||
|
|
|
@ -1,5 +1,24 @@
|
|||
var GetFastValue = require('../../utils/object/GetFastValue');
|
||||
|
||||
/**
|
||||
* Parses a Sprite Sheet and adds the Frames to the Texture.
|
||||
*
|
||||
* In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact
|
||||
* same size and cannot be trimmed or rotated.
|
||||
*
|
||||
* @function Phaser.Textures.Parsers.SpriteSheet
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
|
||||
* @param {integer} sourceIndex - The index of the TextureSource.
|
||||
* @param {integer} x - [description]
|
||||
* @param {integer} y - [description]
|
||||
* @param {integer} width - [description]
|
||||
* @param {integer} height - [description]
|
||||
* @param {object} config - [description]
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
|
||||
*/
|
||||
var SpriteSheet = function (texture, sourceIndex, x, y, width, height, config)
|
||||
{
|
||||
var frameWidth = GetFastValue(config, 'frameWidth', null);
|
||||
|
|
|
@ -1,5 +1,20 @@
|
|||
var GetFastValue = require('../../utils/object/GetFastValue');
|
||||
|
||||
/**
|
||||
* Parses a Sprite Sheet and adds the Frames to the Texture, where the Sprite Sheet is stored as a frame within an Atlas.
|
||||
*
|
||||
* In Phaser terminology a Sprite Sheet is a texture containing different frames, but each frame is the exact
|
||||
* same size and cannot be trimmed or rotated.
|
||||
*
|
||||
* @function Phaser.Textures.Parsers.SpriteSheetFromAtlas
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
|
||||
* @param {Phaser.Textures.Frame} frame - The Frame that contains the Sprite Sheet.
|
||||
* @param {object} config - [description]
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
|
||||
*/
|
||||
var SpriteSheetFromAtlas = function (texture, frame, config)
|
||||
{
|
||||
var frameWidth = GetFastValue(config, 'frameWidth', null);
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
/**
|
||||
* Parses a Starling XML object and adds all the Frames into a Texture.
|
||||
*
|
||||
* @function Phaser.Textures.Parsers.StarlingXML
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
|
||||
* @param {any} xml - The XML data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
|
||||
*/
|
||||
var StarlingXML = function (texture, xml)
|
||||
{
|
||||
// Malformed?
|
||||
|
|
|
@ -1,35 +1,3 @@
|
|||
/*
|
||||
Example data:
|
||||
|
||||
TextureImporter:
|
||||
spritePivot: {x: .5, y: .5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
spriteSheet:
|
||||
sprites:
|
||||
- name: asteroids_0
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 5
|
||||
y: 328
|
||||
width: 65
|
||||
height: 82
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
- name: asteroids_1
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 80
|
||||
y: 322
|
||||
width: 53
|
||||
height: 88
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePackingTag: Asteroids
|
||||
*/
|
||||
|
||||
var imageHeight = 0;
|
||||
|
||||
var addFrame = function (texture, sourceIndex, name, frame)
|
||||
|
@ -58,8 +26,19 @@ var addFrame = function (texture, sourceIndex, name, frame)
|
|||
*/
|
||||
};
|
||||
|
||||
// https://docs.unity3d.com/ScriptReference/SpriteMetaData.html
|
||||
|
||||
/**
|
||||
* Parses a Unity YAML File and creates Frames in the Texture.
|
||||
* For more details about Sprite Meta Data see https://docs.unity3d.com/ScriptReference/SpriteMetaData.html
|
||||
*
|
||||
* @function Phaser.Textures.Parsers.UnityYAML
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Textures.Texture} texture - The Texture to add the Frames to.
|
||||
* @param {integer} sourceIndex - The index of the TextureSource.
|
||||
* @param {object} yaml - The YAML data.
|
||||
*
|
||||
* @return {Phaser.Textures.Texture} The Texture modified by this parser.
|
||||
*/
|
||||
var UnityYAML = function (texture, sourceIndex, yaml)
|
||||
{
|
||||
// Add in a __BASE entry (for the entire atlas)
|
||||
|
@ -139,3 +118,35 @@ var UnityYAML = function (texture, sourceIndex, yaml)
|
|||
};
|
||||
|
||||
module.exports = UnityYAML;
|
||||
|
||||
/*
|
||||
Example data:
|
||||
|
||||
TextureImporter:
|
||||
spritePivot: {x: .5, y: .5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
spriteSheet:
|
||||
sprites:
|
||||
- name: asteroids_0
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 5
|
||||
y: 328
|
||||
width: 65
|
||||
height: 82
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
- name: asteroids_1
|
||||
rect:
|
||||
serializedVersion: 2
|
||||
x: 80
|
||||
y: 322
|
||||
width: 53
|
||||
height: 88
|
||||
alignment: 0
|
||||
pivot: {x: 0, y: 0}
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePackingTag: Asteroids
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
/**
|
||||
* @namespace Phaser.Textures.Parsers
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
|
||||
Canvas: require('./Canvas'),
|
||||
Image: require('./Image'),
|
||||
JSONArray: require('./JSONArray'),
|
||||
|
@ -9,4 +13,5 @@ module.exports = {
|
|||
SpriteSheetFromAtlas: require('./SpriteSheetFromAtlas'),
|
||||
StarlingXML: require('./StarlingXML'),
|
||||
UnityYAML: require('./UnityYAML')
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue