mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 22:52:14 +00:00
BitmapData.addToWorld will create a new Phaser.Image object, assign the BitmapData to be its texture, add it to the world then return it.
BitmapData.copyPixels now accepts a Sprite, Image, BitmapData, HTMLImage or string as its source.
This commit is contained in:
parent
2219e6f1c9
commit
af1508de8f
2 changed files with 38 additions and 6 deletions
|
@ -72,6 +72,8 @@ Version 2.0.6 - "Jornhill" - -in development-
|
|||
* Phaser.Keyboard.lastKey will return the most recently pressed Key object.
|
||||
* RetroFont.updateOffset allows you to modify the offsetX/Y values used by the font during rendering.
|
||||
* ArcadePhysics.Body has a new boolean property `enable`. If `false` the body won't be checked for any collision or overlaps, or have its pre or post update methods called. Use this for easy toggling of physics bodies without having to destroy or re-create the Body object itself.
|
||||
* BitmapData.addToWorld will create a new Phaser.Image object, assign the BitmapData to be its texture, add it to the world then return it.
|
||||
* BitmapData.copyPixels now accepts a Sprite, Image, BitmapData, HTMLImage or string as its source.
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
|
|
@ -750,26 +750,56 @@ Phaser.BitmapData.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new Phaser.Image object, assigns this BitmapData to be its texture, adds it to the world then returns it.
|
||||
*
|
||||
* @method Phaser.BitmapData#addToWorld
|
||||
* @param {number} [x=0] - The x coordinate to place the image at.
|
||||
* @param {number} [y=0] - The y coordinate to place the image at.
|
||||
* @return {Phaser.Image} The newly added Image object.
|
||||
*/
|
||||
addToWorld: function (x, y) {
|
||||
|
||||
return this.game.add.image(x, y, this);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Copies the pixels from the source image to this BitmapData based on the given area and destination.
|
||||
*
|
||||
* @method Phaser.BitmapData#copyPixels
|
||||
* @param {HTMLImage|string} source - The Image to draw. If you give a key it will try and find the Image in the Game.Cache.
|
||||
* @param {Phaser.Sprite|Phaser.Image|Phaser.BitmapData|HTMLImage|string} source - The Image to copy from. If you give a string it will try and find the Image in the Game.Cache.
|
||||
* @param {Phaser.Rectangle} area - The Rectangle region to copy from the source image.
|
||||
* @param {number} destX - The destination x coordinate to copy the image to.
|
||||
* @param {number} destY - The destination y coordinate to copy the image to.
|
||||
* @param {number} x - The destination x coordinate to copy the image to.
|
||||
* @param {number} y - The destination y coordinate to copy the image to.
|
||||
*/
|
||||
copyPixels: function (source, area, destX, destY) {
|
||||
copyPixels: function (source, area, x, y) {
|
||||
|
||||
if (typeof source === 'string')
|
||||
{
|
||||
source = this.game.cache.getImage(source);
|
||||
}
|
||||
|
||||
if (source)
|
||||
var src = source;
|
||||
var sx = 0;
|
||||
var sy = 0;
|
||||
|
||||
if (source instanceof Phaser.Image || source instanceof Phaser.Sprite)
|
||||
{
|
||||
this.context.drawImage(source, area.x, area.y, area.width, area.height, destX, destY, area.width, area.height);
|
||||
src = source.texture.baseTexture.source;
|
||||
var frame = source.texture.frame;
|
||||
sx = frame.x;
|
||||
sy = frame.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (source instanceof Phaser.BitmapData)
|
||||
{
|
||||
src = source.canvas;
|
||||
}
|
||||
}
|
||||
|
||||
this.context.drawImage(src, sx + area.x, sy + area.y, area.width, area.height, x, y, area.width, area.height);
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
|
|
Loading…
Reference in a new issue