copy(source, x, y, width, height, tx, ty, newWidth, newHeight, rotate, anchorX, anchorY, scaleX, scaleY, alpha, blendMode, roundPx) → {Phaser.BitmapData}
Copies a rectangular area from the source object to this BitmapData. If you give null
as the source it will copy from itself.
You can optionally resize, translate, rotate, scale, alpha or blend as it's drawn.
All rotation, scaling and drawing takes place around the regions center point by default, but can be changed with the anchor parameters.
Note that the source image can also be this BitmapData, which can create some interesting effects.
This method has a lot of parameters for maximum control.
You can use the more friendly methods like copyRect
and draw
to avoid having to remember them all.
You may prefer to use copyTransform
if you're simply trying to draw a Sprite to this BitmapData,
and don't wish to translate, scale or rotate it from its original values.
Parameters
Name | Type | Argument | Default | Description |
---|---|---|---|---|
source | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapData | Phaser.RenderTexture | Image | HTMLCanvasElement | string | <optional> | The source to copy from. If you give a string it will try and find the Image in the Game.Cache first. This is quite expensive so try to provide the image itself. | |
x | number | <optional> | 0 | The x coordinate representing the top-left of the region to copy from the source image. |
y | number | <optional> | 0 | The y coordinate representing the top-left of the region to copy from the source image. |
width | number | <optional> | The width of the region to copy from the source image. If not specified it will use the full source image width. | |
height | number | <optional> | The height of the region to copy from the source image. If not specified it will use the full source image height. | |
tx | number | <optional> | The x coordinate to translate to before drawing. If not specified it will default to the | |
ty | number | <optional> | The y coordinate to translate to before drawing. If not specified it will default to the | |
newWidth | number | <optional> | The new width of the block being copied. If not specified it will default to the | |
newHeight | number | <optional> | The new height of the block being copied. If not specified it will default to the | |
rotate | number | <optional> | 0 | The angle in radians to rotate the block to before drawing. Rotation takes place around the center by default, but can be changed with the |
anchorX | number | <optional> | 0 | The anchor point around which the block is rotated and scaled. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. |
anchorY | number | <optional> | 0 | The anchor point around which the block is rotated and scaled. A value between 0 and 1, where 0 is the top-left and 1 is bottom-right. |
scaleX | number | <optional> | 1 | The horizontal scale factor of the block. A value of 1 means no scaling. 2 would be twice the size, and so on. |
scaleY | number | <optional> | 1 | The vertical scale factor of the block. A value of 1 means no scaling. 2 would be twice the size, and so on. |
alpha | number | <optional> | 1 | The alpha that will be set on the context before drawing. A value between 0 (fully transparent) and 1, opaque. |
blendMode | string | <optional> | null | The composite blend mode that will be used when drawing. The default is no blend mode at all. This is a Canvas globalCompositeOperation value such as 'lighter' or 'xor'. |
roundPx | boolean | <optional> | false | Should the x and y values be rounded to integers before drawing? This prevents anti-aliasing in some instances. |
Returns
This BitmapData object for method chaining.
- Source code: gameobjects/BitmapData.js (Line 1205)
Please login to continue.