2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2014-02-05 05:54:25 +00:00
|
|
|
* @copyright 2014 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-07-31 12:39:12 +00:00
|
|
|
* A RenderTexture is a special texture that allows any displayObject to be rendered to it. It allows you to take many complex objects and
|
|
|
|
* render them down into a single quad (on WebGL) which can then be used to texture other display objects with. A way of generating textures at run-time.
|
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @class Phaser.RenderTexture
|
|
|
|
* @constructor
|
2014-09-16 16:35:08 +00:00
|
|
|
* @extends PIXI.RenderTexture
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {Phaser.Game} game - Current game instance.
|
2014-02-07 06:25:28 +00:00
|
|
|
* @param {string} key - Internal Phaser reference key for the render texture.
|
|
|
|
* @param {number} [width=100] - The width of the render texture.
|
|
|
|
* @param {number} [height=100] - The height of the render texture.
|
2014-05-15 14:32:59 +00:00
|
|
|
* @param {string} [key=''] - The key of the RenderTexture in the Cache, if stored there.
|
|
|
|
* @param {number} [scaleMode=Phaser.scaleModes.DEFAULT] - One of the Phaser.scaleModes consts.
|
2014-10-22 20:20:38 +00:00
|
|
|
* @param {number} [resolution=1] - The resolution of the texture being generated.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-10-22 20:20:38 +00:00
|
|
|
Phaser.RenderTexture = function (game, width, height, key, scaleMode, resolution) {
|
2014-05-15 14:32:59 +00:00
|
|
|
|
|
|
|
if (typeof key === 'undefined') { key = ''; }
|
|
|
|
if (typeof scaleMode === 'undefined') { scaleMode = Phaser.scaleModes.DEFAULT; }
|
2014-10-22 20:20:38 +00:00
|
|
|
if (typeof resolution === 'undefined') { resolution = 1; }
|
2013-09-10 00:26:50 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-03-23 07:59:28 +00:00
|
|
|
* @property {Phaser.Game} game - A reference to the currently running game.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
|
|
|
this.game = game;
|
2013-09-10 00:26:50 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-02-07 06:25:28 +00:00
|
|
|
* @property {string} key - The key of the RenderTexture in the Cache, if stored there.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2014-02-07 06:25:28 +00:00
|
|
|
this.key = key;
|
2013-09-10 00:26:50 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-03-23 07:59:28 +00:00
|
|
|
* @property {number} type - Base Phaser object type.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this.type = Phaser.RENDERTEXTURE;
|
|
|
|
|
2014-02-21 13:44:39 +00:00
|
|
|
/**
|
2014-10-22 20:20:38 +00:00
|
|
|
* @property {PIXI.Matrix} matrix - The matrix that is applied when display objects are rendered to this RenderTexture.
|
2014-02-21 13:44:39 +00:00
|
|
|
*/
|
2014-10-22 20:20:38 +00:00
|
|
|
this.matrix = new PIXI.Matrix();
|
2014-02-21 13:44:39 +00:00
|
|
|
|
2014-10-22 20:20:38 +00:00
|
|
|
PIXI.RenderTexture.call(this, width, height, this.game.renderer, scaleMode, resolution);
|
|
|
|
|
|
|
|
this.render = Phaser.RenderTexture.prototype.render;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-09-10 00:26:50 +00:00
|
|
|
};
|
|
|
|
|
2014-02-07 02:31:29 +00:00
|
|
|
Phaser.RenderTexture.prototype = Object.create(PIXI.RenderTexture.prototype);
|
|
|
|
Phaser.RenderTexture.prototype.constructor = Phaser.RenderTexture;
|
2014-02-21 13:44:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will draw the display object to the texture.
|
|
|
|
*
|
|
|
|
* @method Phaser.RenderTexture.prototype.renderXY
|
|
|
|
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Group} displayObject The display object to render to this texture.
|
|
|
|
* @param {number} x - The x position to render the object at.
|
|
|
|
* @param {number} y - The y position to render the object at.
|
|
|
|
* @param {boolean} clear - If true the texture will be cleared before the display object is drawn.
|
|
|
|
*/
|
|
|
|
Phaser.RenderTexture.prototype.renderXY = function (displayObject, x, y, clear) {
|
|
|
|
|
2014-10-22 20:20:38 +00:00
|
|
|
this.matrix.tx = x;
|
|
|
|
this.matrix.ty = y;
|
2014-02-21 13:44:39 +00:00
|
|
|
|
2014-10-22 20:20:38 +00:00
|
|
|
if (this.renderer.type === PIXI.WEBGL_RENDERER)
|
|
|
|
{
|
|
|
|
this.renderWebGL(displayObject, this.matrix, clear);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.renderCanvas(displayObject, this.matrix, clear);
|
|
|
|
}
|
2014-02-21 13:44:39 +00:00
|
|
|
|
2014-03-23 08:40:24 +00:00
|
|
|
};
|
2014-02-21 13:44:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will draw the display object to the texture.
|
|
|
|
*
|
|
|
|
* @method Phaser.RenderTexture.prototype.render
|
|
|
|
* @param {Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Group} displayObject The display object to render to this texture.
|
|
|
|
* @param {Phaser.Point} position - A Point object containing the position to render the display object at.
|
|
|
|
* @param {boolean} clear - If true the texture will be cleared before the display object is drawn.
|
|
|
|
*/
|
2014-10-22 20:20:38 +00:00
|
|
|
Phaser.RenderTexture.prototype.render = function (displayObject, position, clear) {
|
2014-02-21 13:44:39 +00:00
|
|
|
|
2014-10-22 20:20:38 +00:00
|
|
|
this.matrix.tx = position.x;
|
|
|
|
this.matrix.ty = position.y;
|
|
|
|
|
|
|
|
if (this.renderer.type === PIXI.WEBGL_RENDERER)
|
|
|
|
{
|
|
|
|
this.renderWebGL(displayObject, this.matrix, clear);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.renderCanvas(displayObject, this.matrix, clear);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|