BitmapData.textureLine takes a Phaser.Line object and an image in the image cache. It then accurately draws the image as a repeating texture for the full length of the line.

This commit is contained in:
photonstorm 2014-10-03 02:21:09 +01:00
parent 173786c60d
commit ab78710daa
3 changed files with 36 additions and 1 deletions

View file

@ -92,6 +92,7 @@ Version 2.1.2 - "Whitebridge" - in development
* Cache.addBitmapData has a new parameter: `frameData` allowing you to pass a `Phaser.FrameData` object along with the BitmapData.
* Cache.getFrameData has a new parameter: `map` which allows you to specify which cache to get the FrameData from, i.e. `Phaser.Cache.IMAGE` or `Phaser.Cache.BITMAPDATA`.
* Sprite.loadTexture if given a BitmapData as the texture will now query the cache to see if it has any associated FrameData, and if so it will load that into the AnimationManager.
* BitmapData.textureLine takes a Phaser.Line object and an image in the image cache. It then accurately draws the image as a repeating texture for the full length of the line.

View file

@ -193,6 +193,12 @@ Phaser.BitmapData = function (game, key, width, height) {
*/
this._tempB = 0;
/**
* @property {Phaser.Circle} _circle - Internal cache var.
* @private
*/
this._circle = new Phaser.Circle();
};
Phaser.BitmapData.prototype = {
@ -1237,6 +1243,34 @@ Phaser.BitmapData.prototype = {
},
/**
* Takes the given Line object and image and renders it to this BitmapData as a repeating texture line.
*
* @method Phaser.BitmapData#textureLine
* @param {Phaser.Line} line - A Phaser.Line object that will be used to plot the start and end of the line.
* @param {string} key - The key of an image in the Phaser.Cache to use as the texture for this line.
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
*/
textureLine: function (line, key) {
var image = this.game.cache.getImage(key);
this._circle = new Phaser.Circle(line.start.x, line.start.y, image.height);
circle.circumferencePoint(line.angle - 1.5707963267948966, false, this._pos);
this.context.save();
this.context.translate(this._pos.x, this._pos.y);
this.context.rotate(line.angle);
this.context.fillRect(0, 0, line.length, image.height);
this.context.restore();
this.dirty = true;
return this;
},
/**
* If the game is running in WebGL this will push the texture up to the GPU if it's dirty.
* This is called automatically if the BitmapData is being used by a Sprite, otherwise you need to remember to call it in your render function.

View file

@ -67,7 +67,7 @@ Phaser.Circle.prototype = {
* @method Phaser.Circle#setTo
* @param {number} x - The x coordinate of the center of the circle.
* @param {number} y - The y coordinate of the center of the circle.
* @param {number} diameter - The diameter of the circle in pixels.
* @param {number} diameter - The diameter of the circle.
* @return {Circle} This circle object.
*/
setTo: function (x, y, diameter) {