Skip to content

Commit ab78710

Browse files
committed
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.
1 parent 173786c commit ab78710

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Version 2.1.2 - "Whitebridge" - in development
9292
* Cache.addBitmapData has a new parameter: `frameData` allowing you to pass a `Phaser.FrameData` object along with the BitmapData.
9393
* 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`.
9494
* 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.
95+
* 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.
9596

9697

9798

src/gameobjects/BitmapData.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ Phaser.BitmapData = function (game, key, width, height) {
193193
*/
194194
this._tempB = 0;
195195

196+
/**
197+
* @property {Phaser.Circle} _circle - Internal cache var.
198+
* @private
199+
*/
200+
this._circle = new Phaser.Circle();
201+
196202
};
197203

198204
Phaser.BitmapData.prototype = {
@@ -1237,6 +1243,34 @@ Phaser.BitmapData.prototype = {
12371243

12381244
},
12391245

1246+
/**
1247+
* Takes the given Line object and image and renders it to this BitmapData as a repeating texture line.
1248+
*
1249+
* @method Phaser.BitmapData#textureLine
1250+
* @param {Phaser.Line} line - A Phaser.Line object that will be used to plot the start and end of the line.
1251+
* @param {string} key - The key of an image in the Phaser.Cache to use as the texture for this line.
1252+
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
1253+
*/
1254+
textureLine: function (line, key) {
1255+
1256+
var image = this.game.cache.getImage(key);
1257+
1258+
this._circle = new Phaser.Circle(line.start.x, line.start.y, image.height);
1259+
1260+
circle.circumferencePoint(line.angle - 1.5707963267948966, false, this._pos);
1261+
1262+
this.context.save();
1263+
this.context.translate(this._pos.x, this._pos.y);
1264+
this.context.rotate(line.angle);
1265+
this.context.fillRect(0, 0, line.length, image.height);
1266+
this.context.restore();
1267+
1268+
this.dirty = true;
1269+
1270+
return this;
1271+
1272+
},
1273+
12401274
/**
12411275
* If the game is running in WebGL this will push the texture up to the GPU if it's dirty.
12421276
* 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.

src/geom/Circle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Phaser.Circle.prototype = {
6767
* @method Phaser.Circle#setTo
6868
* @param {number} x - The x coordinate of the center of the circle.
6969
* @param {number} y - The y coordinate of the center of the circle.
70-
* @param {number} diameter - The diameter of the circle in pixels.
70+
* @param {number} diameter - The diameter of the circle.
7171
* @return {Circle} This circle object.
7272
*/
7373
setTo: function (x, y, diameter) {

0 commit comments

Comments
 (0)