This commit is contained in:
Richard Davey 2018-12-13 10:25:58 +00:00
commit a4badb68ad
2 changed files with 50 additions and 0 deletions

View file

@ -161,6 +161,8 @@ one set of bindings ever created, which makes things a lot cleaner.
* `CanvasTexture.getIndex` is a new method that will take an x/y coordinate and return the Image Data index offset used to retrieve the pixel values.
* `CanvasTexture.getPixels` is a new method that will take a region as an x/y and width/height and return all of the pixels in that region from the CanvasTexture.
* `CanvasTexture.setPixel` is a new method that sets the given pixel in the CanvasTexture to the color and alpha values provided.
* `CanvasTexture.getData` is a new method that will extract an ImageData block from the CanvasTexture from the region given.
* `CanvasTexture.putData` is a new method that will put an ImageData block at the given coordinates in a CanvasTexture.
### Updates

View file

@ -312,6 +312,54 @@ var CanvasTexture = new Class({
return this;
},
/**
* Puts the ImageData into the context of this CanvasTexture at the given coordinates.
*
* @method Phaser.Textures.CanvasTexture#putData
* @since 3.16.0
*
* @param {ImageData} imageData - The ImageData to put at the given location.
* @param {integer} x - The x coordinate to put the imageData. Must lay within the dimensions of this CanvasTexture and be an integer.
* @param {integer} y - The y coordinate to put the imageData. Must lay within the dimensions of this CanvasTexture and be an integer.
*
* @return {this} This CanvasTexture.
*/
putData: function (imageData, x, y)
{
x = Math.abs(Math.floor(x));
y = Math.abs(Math.floor(y));
this.context.putImageData(imageData, x, y);
return this;
},
/**
* Gets an ImageData region from this CanvasTexture from the position and size specified.
* You can write this back using `CanvasTexture.putData`, or manipulate it.
*
* @method Phaser.Textures.CanvasTexture#getData
* @since 3.16.0
*
* @param {integer} x - The x coordinate of the top-left of the area to get the ImageData from. Must lay within the dimensions of this CanvasTexture and be an integer.
* @param {integer} y - The y coordinate of the top-left of the area to get the ImageData from. Must lay within the dimensions of this CanvasTexture and be an integer.
* @param {integer} width - The width of the region to get. Must be an integer.
* @param {integer} height - The height of the region to get. Must be an integer.
*
* @return {ImageData} The ImageData extracted from this CanvasTexture.
*/
getData: function (x, y, width, height)
{
x = Clamp(Math.floor(x), 0, this.width - 1);
y = Clamp(Math.floor(y), 0, this.height - 1);
width = Clamp(width, 1, this.width - x);
height = Clamp(height, 1, this.height - y);
var imageData = this.context.getImageData(x, y, width, height);
return imageData;
},
/**
* Get the color of a specific pixel from this texture and store it in a Color object.
*