2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2022-02-28 14:29:51 +00:00
|
|
|
* @copyright 2022 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
var Class = require('../utils/Class');
|
2016-12-06 16:18:28 +00:00
|
|
|
var Frame = require('./Frame');
|
|
|
|
var TextureSource = require('./TextureSource');
|
|
|
|
|
2021-09-02 17:41:16 +00:00
|
|
|
var TEXTURE_MISSING_ERROR = 'Texture "%s" has no frame "%s"';
|
2018-08-02 11:33:48 +00:00
|
|
|
|
2016-12-06 16:18:28 +00:00
|
|
|
/**
|
2018-02-08 04:01:44 +00:00
|
|
|
* @classdesc
|
2018-04-23 22:40:23 +00:00
|
|
|
* 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
|
2018-02-08 04:01:44 +00:00
|
|
|
* 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.
|
2020-11-23 10:32:00 +00:00
|
|
|
*
|
2019-04-08 10:54:47 +00:00
|
|
|
* Every Texture, no matter where it comes from, always has at least 1 frame called the `__BASE` frame.
|
|
|
|
* This frame represents the entirety of the source image.
|
2018-02-08 04:01:44 +00:00
|
|
|
*
|
|
|
|
* 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
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Textures
|
2018-02-08 04:01:44 +00:00
|
|
|
* @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.
|
2018-12-13 09:17:09 +00:00
|
|
|
* @param {(HTMLImageElement|HTMLCanvasElement|HTMLImageElement[]|HTMLCanvasElement[])} source - An array of sources that are used to create the texture. Usually Images, but can also be a Canvas.
|
2018-02-08 04:01:44 +00:00
|
|
|
* @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.
|
|
|
|
*/
|
2017-07-04 12:23:58 +00:00
|
|
|
var Texture = new Class({
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
initialize:
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
function Texture (manager, key, source, width, height)
|
|
|
|
{
|
|
|
|
if (!Array.isArray(source))
|
|
|
|
{
|
|
|
|
source = [ source ];
|
|
|
|
}
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-07-04 12:23:58 +00:00
|
|
|
this.key = key;
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
/**
|
2018-02-08 04:01:44 +00:00
|
|
|
* 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
|
|
|
|
*/
|
2017-07-04 12:23:58 +00:00
|
|
|
this.source = [];
|
2017-03-27 22:38:27 +00:00
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2018-01-29 23:38:27 +00:00
|
|
|
this.dataSource = [];
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-07-04 12:23:58 +00:00
|
|
|
this.frames = {};
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2018-01-19 18:23:25 +00:00
|
|
|
this.customData = {};
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* The name of the first frame of the Texture.
|
|
|
|
*
|
|
|
|
* @name Phaser.Textures.Texture#firstFrame
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 12:23:58 +00:00
|
|
|
this.firstFrame = '__BASE';
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
2019-04-08 10:54:47 +00:00
|
|
|
* The total number of Frames in this Texture, including the `__BASE` frame.
|
2020-11-23 10:32:00 +00:00
|
|
|
*
|
2019-04-08 10:54:47 +00:00
|
|
|
* A Texture will always contain at least 1 frame because every Texture contains a `__BASE` frame by default,
|
|
|
|
* in addition to any extra frames that have been added to it, such as when parsing a Sprite Sheet or Texture Atlas.
|
2018-02-08 04:01:44 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Textures.Texture#frameTotal
|
2020-11-23 10:22:13 +00:00
|
|
|
* @type {number}
|
2018-02-08 04:01:44 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 12:23:58 +00:00
|
|
|
this.frameTotal = 0;
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
// Load the Sources
|
|
|
|
for (var i = 0; i < source.length; i++)
|
|
|
|
{
|
|
|
|
this.source.push(new TextureSource(this, source[i], width, height));
|
|
|
|
}
|
|
|
|
},
|
2016-12-06 16:18:28 +00:00
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* Adds a new Frame to this Texture.
|
|
|
|
*
|
|
|
|
* A Frame is a rectangular region of a TextureSource with a unique index or string-based key.
|
2020-11-23 10:32:00 +00:00
|
|
|
*
|
2019-04-08 13:22:03 +00:00
|
|
|
* The name given must be unique within this Texture. If it already exists, this method will return `null`.
|
2018-02-08 04:01:44 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Textures.Texture#add
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(number|string)} name - The name of this Frame. The name is unique within the Texture.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} sourceIndex - The index of the TextureSource that this Frame is a part of.
|
2018-02-08 04:01:44 +00:00
|
|
|
* @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.
|
|
|
|
*
|
2019-04-08 13:22:03 +00:00
|
|
|
* @return {?Phaser.Textures.Frame} The Frame that was added to this Texture, or `null` if the given name already exists.
|
2018-02-08 04:01:44 +00:00
|
|
|
*/
|
2016-12-06 16:18:28 +00:00
|
|
|
add: function (name, sourceIndex, x, y, width, height)
|
|
|
|
{
|
2019-04-08 13:22:03 +00:00
|
|
|
if (this.has(name))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-12-06 16:18:28 +00:00
|
|
|
var frame = new Frame(this, name, sourceIndex, x, y, width, height);
|
|
|
|
|
|
|
|
this.frames[name] = frame;
|
|
|
|
|
2017-03-27 22:38:27 +00:00
|
|
|
// Set the first frame of the Texture (other than __BASE)
|
|
|
|
// This is used to ensure we don't spam the display with entire
|
|
|
|
// atlases of sprite sheets, but instead just the first frame of them
|
|
|
|
// should the dev incorrectly specify the frame index
|
2018-10-04 18:29:17 +00:00
|
|
|
if (this.firstFrame === '__BASE')
|
2017-03-27 22:38:27 +00:00
|
|
|
{
|
|
|
|
this.firstFrame = name;
|
|
|
|
}
|
|
|
|
|
2016-12-06 16:18:28 +00:00
|
|
|
this.frameTotal++;
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
},
|
|
|
|
|
2019-08-07 12:03:00 +00:00
|
|
|
/**
|
|
|
|
* Removes the given Frame from this Texture. The Frame is destroyed immediately.
|
2020-11-23 10:32:00 +00:00
|
|
|
*
|
2019-08-07 12:03:00 +00:00
|
|
|
* Any Game Objects using this Frame should stop using it _before_ you remove it,
|
|
|
|
* as it does not happen automatically.
|
|
|
|
*
|
|
|
|
* @method Phaser.Textures.Texture#remove
|
|
|
|
* @since 3.19.0
|
|
|
|
*
|
|
|
|
* @param {string} name - The key of the Frame to remove.
|
|
|
|
*
|
|
|
|
* @return {boolean} True if a Frame with the matching key was removed from this Texture.
|
|
|
|
*/
|
|
|
|
remove: function (name)
|
|
|
|
{
|
|
|
|
if (this.has(name))
|
|
|
|
{
|
|
|
|
var frame = this.get(name);
|
|
|
|
|
|
|
|
frame.destroy();
|
|
|
|
|
|
|
|
delete this.frames[name];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-04-05 16:04:55 +00:00
|
|
|
has: function (name)
|
|
|
|
{
|
|
|
|
return (this.frames[name]);
|
|
|
|
},
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number)} [name] - The string-based name, or integer based index, of the Frame to get from this Texture.
|
2018-02-08 04:01:44 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Textures.Frame} The Texture Frame.
|
|
|
|
*/
|
2016-12-06 16:18:28 +00:00
|
|
|
get: function (name)
|
|
|
|
{
|
2018-03-01 00:36:50 +00:00
|
|
|
// null, undefined, empty string, zero
|
|
|
|
if (!name)
|
2016-12-06 16:18:28 +00:00
|
|
|
{
|
2018-03-01 00:36:50 +00:00
|
|
|
name = this.firstFrame;
|
2016-12-06 16:18:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var frame = this.frames[name];
|
|
|
|
|
|
|
|
if (!frame)
|
|
|
|
{
|
2021-09-02 17:41:16 +00:00
|
|
|
console.warn(TEXTURE_MISSING_ERROR, this.key, name);
|
2018-03-20 15:10:19 +00:00
|
|
|
|
2018-03-01 00:36:50 +00:00
|
|
|
frame = this.frames[this.firstFrame];
|
2016-12-06 16:18:28 +00:00
|
|
|
}
|
2018-03-20 15:10:19 +00:00
|
|
|
|
2018-03-01 00:36:50 +00:00
|
|
|
return frame;
|
2016-12-06 16:18:28 +00:00
|
|
|
},
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @return {number} The index of the TextureSource within this Texture, or -1 if not in this Texture.
|
2018-02-08 04:01:44 +00:00
|
|
|
*/
|
2017-10-18 12:45:11 +00:00
|
|
|
getTextureSourceIndex: function (source)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < this.source.length; i++)
|
|
|
|
{
|
|
|
|
if (this.source[i] === source)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* Returns an array of all the Frames in the given TextureSource.
|
|
|
|
*
|
|
|
|
* @method Phaser.Textures.Texture#getFramesFromTextureSource
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} sourceIndex - The index of the TextureSource to get the Frames from.
|
2018-09-27 13:11:14 +00:00
|
|
|
* @param {boolean} [includeBase=false] - Include the `__BASE` Frame in the output array?
|
2018-02-08 04:01:44 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.Textures.Frame[]} An array of Texture Frames.
|
|
|
|
*/
|
2018-09-27 13:11:14 +00:00
|
|
|
getFramesFromTextureSource: function (sourceIndex, includeBase)
|
2017-10-18 12:45:11 +00:00
|
|
|
{
|
2018-09-27 13:11:14 +00:00
|
|
|
if (includeBase === undefined) { includeBase = false; }
|
|
|
|
|
2017-10-18 12:45:11 +00:00
|
|
|
var out = [];
|
|
|
|
|
|
|
|
for (var frameName in this.frames)
|
|
|
|
{
|
2018-09-27 13:11:14 +00:00
|
|
|
if (frameName === '__BASE' && !includeBase)
|
2017-10-18 12:45:11 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var frame = this.frames[frameName];
|
|
|
|
|
|
|
|
if (frame.sourceIndex === sourceIndex)
|
|
|
|
{
|
2018-09-27 13:11:14 +00:00
|
|
|
out.push(frame);
|
2017-10-18 12:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
},
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* Returns an array with all of the names of the Frames in this Texture.
|
2018-03-20 15:10:19 +00:00
|
|
|
*
|
2018-02-08 04:01:44 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2017-04-28 03:30:32 +00:00
|
|
|
getFrameNames: function (includeBase)
|
|
|
|
{
|
|
|
|
if (includeBase === undefined) { includeBase = false; }
|
|
|
|
|
|
|
|
var out = Object.keys(this.frames);
|
|
|
|
|
|
|
|
if (!includeBase)
|
|
|
|
{
|
|
|
|
var idx = out.indexOf('__BASE');
|
|
|
|
|
|
|
|
if (idx !== -1)
|
|
|
|
{
|
|
|
|
out.splice(idx, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
},
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number)} [name] - The string-based name, or integer based index, of the Frame to get from this Texture.
|
2018-02-08 04:01:44 +00:00
|
|
|
*
|
2018-08-02 11:33:48 +00:00
|
|
|
* @return {(HTMLImageElement|HTMLCanvasElement|Phaser.GameObjects.RenderTexture)} The DOM Image, Canvas Element or Render Texture.
|
2018-02-08 04:01:44 +00:00
|
|
|
*/
|
2017-03-14 16:37:32 +00:00
|
|
|
getSourceImage: function (name)
|
|
|
|
{
|
|
|
|
if (name === undefined || name === null || this.frameTotal === 1)
|
|
|
|
{
|
|
|
|
name = '__BASE';
|
|
|
|
}
|
|
|
|
|
|
|
|
var frame = this.frames[name];
|
|
|
|
|
2018-08-02 16:59:19 +00:00
|
|
|
if (frame)
|
|
|
|
{
|
|
|
|
return frame.source.image;
|
|
|
|
}
|
|
|
|
else
|
2017-03-14 16:37:32 +00:00
|
|
|
{
|
2021-09-02 17:41:16 +00:00
|
|
|
console.warn(TEXTURE_MISSING_ERROR, this.key, name);
|
2017-03-14 16:37:32 +00:00
|
|
|
|
2018-08-02 16:59:19 +00:00
|
|
|
return this.frames['__BASE'].source.image;
|
2017-03-14 16:37:32 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-05-04 13:33:02 +00:00
|
|
|
/**
|
|
|
|
* Given a Frame name, return the data source image it uses to render with.
|
|
|
|
* You can use this to get the normal map for an image for example.
|
|
|
|
*
|
|
|
|
* This will return the actual DOM Image.
|
|
|
|
*
|
|
|
|
* @method Phaser.Textures.Texture#getDataSourceImage
|
|
|
|
* @since 3.7.0
|
|
|
|
*
|
2020-11-23 10:32:00 +00:00
|
|
|
* @param {(string|number)} [name] - The string-based name, or integer based index, of the Frame to get from this Texture.
|
2018-05-04 13:33:02 +00:00
|
|
|
*
|
|
|
|
* @return {(HTMLImageElement|HTMLCanvasElement)} The DOM Image or Canvas Element.
|
|
|
|
*/
|
|
|
|
getDataSourceImage: function (name)
|
|
|
|
{
|
|
|
|
if (name === undefined || name === null || this.frameTotal === 1)
|
|
|
|
{
|
|
|
|
name = '__BASE';
|
|
|
|
}
|
|
|
|
|
|
|
|
var frame = this.frames[name];
|
|
|
|
var idx;
|
|
|
|
|
|
|
|
if (!frame)
|
|
|
|
{
|
2021-09-02 17:41:16 +00:00
|
|
|
console.warn(TEXTURE_MISSING_ERROR, this.key, name);
|
2018-05-04 13:33:02 +00:00
|
|
|
|
|
|
|
idx = this.frames['__BASE'].sourceIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx = frame.sourceIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.dataSource[idx].image;
|
|
|
|
},
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* Adds a data source image to this Texture.
|
2018-03-20 15:10:19 +00:00
|
|
|
*
|
2018-02-08 04:01:44 +00:00
|
|
|
* 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
|
|
|
|
*
|
2018-12-13 09:17:09 +00:00
|
|
|
* @param {(HTMLImageElement|HTMLCanvasElement|HTMLImageElement[]|HTMLCanvasElement[])} data - The source image.
|
2018-02-08 04:01:44 +00:00
|
|
|
*/
|
2018-01-29 23:38:27 +00:00
|
|
|
setDataSource: function (data)
|
|
|
|
{
|
|
|
|
if (!Array.isArray(data))
|
|
|
|
{
|
|
|
|
data = [ data ];
|
|
|
|
}
|
2020-11-23 10:32:00 +00:00
|
|
|
|
2018-01-29 23:38:27 +00:00
|
|
|
for (var i = 0; i < data.length; i++)
|
|
|
|
{
|
|
|
|
var source = this.source[i];
|
|
|
|
|
|
|
|
this.dataSource.push(new TextureSource(this, data[i], source.width, source.height));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2018-03-30 12:57:17 +00:00
|
|
|
* @param {Phaser.Textures.FilterMode} filterMode - The Filter Mode.
|
2018-02-08 04:01:44 +00:00
|
|
|
*/
|
2017-05-20 01:16:45 +00:00
|
|
|
setFilter: function (filterMode)
|
|
|
|
{
|
2018-01-31 03:38:10 +00:00
|
|
|
var i;
|
|
|
|
|
|
|
|
for (i = 0; i < this.source.length; i++)
|
2017-05-20 01:16:45 +00:00
|
|
|
{
|
|
|
|
this.source[i].setFilter(filterMode);
|
|
|
|
}
|
2018-01-29 23:38:27 +00:00
|
|
|
|
2018-01-31 03:38:10 +00:00
|
|
|
for (i = 0; i < this.dataSource.length; i++)
|
2018-01-29 23:38:27 +00:00
|
|
|
{
|
|
|
|
this.dataSource[i].setFilter(filterMode);
|
|
|
|
}
|
2017-07-04 12:23:58 +00:00
|
|
|
},
|
|
|
|
|
2018-02-08 04:01:44 +00:00
|
|
|
/**
|
|
|
|
* Destroys this Texture and releases references to its sources and frames.
|
|
|
|
*
|
|
|
|
* @method Phaser.Textures.Texture#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-04 12:23:58 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
2018-01-31 03:38:10 +00:00
|
|
|
var i;
|
2022-09-21 13:06:58 +00:00
|
|
|
var source = this.source;
|
|
|
|
var dataSource = this.dataSource;
|
2018-01-31 03:38:10 +00:00
|
|
|
|
2022-09-21 13:06:58 +00:00
|
|
|
for (i = 0; i < source.length; i++)
|
2018-01-31 03:38:10 +00:00
|
|
|
{
|
2022-09-21 13:06:58 +00:00
|
|
|
if (source[i])
|
|
|
|
{
|
|
|
|
source[i].destroy();
|
|
|
|
}
|
2018-01-31 03:38:10 +00:00
|
|
|
}
|
|
|
|
|
2022-09-21 13:06:58 +00:00
|
|
|
for (i = 0; i < dataSource.length; i++)
|
2018-01-31 03:38:10 +00:00
|
|
|
{
|
2022-09-21 13:06:58 +00:00
|
|
|
if (dataSource[i])
|
|
|
|
{
|
|
|
|
dataSource[i].destroy();
|
|
|
|
}
|
2018-01-31 03:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var frameName in this.frames)
|
|
|
|
{
|
|
|
|
var frame = this.frames[frameName];
|
|
|
|
|
2022-09-21 13:06:58 +00:00
|
|
|
if (frame)
|
|
|
|
{
|
|
|
|
frame.destroy();
|
|
|
|
}
|
2018-01-31 03:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.source = [];
|
|
|
|
this.dataSource = [];
|
|
|
|
this.frames = {};
|
2019-04-06 10:35:58 +00:00
|
|
|
|
|
|
|
this.manager.removeKey(this.key);
|
|
|
|
|
2018-04-23 16:30:18 +00:00
|
|
|
this.manager = null;
|
2016-12-06 16:18:28 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 12:23:58 +00:00
|
|
|
});
|
2016-12-06 16:18:28 +00:00
|
|
|
|
|
|
|
module.exports = Texture;
|