new BitmapData(game, key, width, height)
Creates a new BitmapData object.
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
game |
Phaser.Game | A reference to the currently running game. |
||
key |
string | Internal Phaser reference key for the render texture. |
||
width |
number |
<optional> |
100 | The width of the BitmapData in pixels. |
height |
number |
<optional> |
100 | The height of the BitmapData in pixels. |
- Source:
Members
-
baseTexture
-
- Source:
Properties:
Name Type Description baseTexture
PIXI.BaseTexture The PIXI.BaseTexture.
-
canvas
-
- Source:
Properties:
Name Type Description canvas
HTMLCanvasElement The canvas to which this BitmapData draws.
-
context
-
- Source:
Properties:
Name Type Description context
CanvasRenderingContext2D The 2d context of the canvas.
-
ctx
-
- Source:
Properties:
Name Type Description ctx
CanvasRenderingContext2D A reference to BitmapData.context.
-
game
-
- Source:
Properties:
Name Type Description game
Phaser.Game A reference to the currently running game.
-
height
-
- Source:
Properties:
Name Type Description height
number The height of the BitmapData in pixels.
-
imageData
-
- Source:
Properties:
Name Type Description imageData
array The canvas image data.
-
key
-
- Source:
Properties:
Name Type Description key
string The key of the BitmapData in the Cache, if stored there.
-
pixels
-
- Source:
Properties:
Name Type Description pixels
UInt8Clamped A reference to the context imageData buffer.
-
texture
-
- Source:
Properties:
Name Type Description texture
PIXI.Texture The PIXI.Texture.
-
textureFrame
-
- Source:
Properties:
Name Type Description textureFrame
Phaser.Frame The Frame this BitmapData uses for rendering.
-
type
-
- Source:
Properties:
Name Type Description type
number The const type of this object.
-
width
-
- Source:
Properties:
Name Type Description width
number The width of the BitmapData in pixels.
Methods
-
add(object)
-
Updates the given objects so that they use this BitmapData as their texture. This will replace any texture they will currently have set.
Parameters:
Name Type Description object
Phaser.Sprite | Array.<Phaser.Sprite> | Phaser.Image | Array.<Phaser.Image> Either a single Sprite/Image or an Array of Sprites/Images.
- Source:
-
alphaMask(source, mask)
-
Draws the given image onto this BitmapData using an image as an alpha mask.
Parameters:
Name Type Description source
HTMLImage | string The Image to draw. If you give a key it will try and find the Image in the Game.Cache.
mask
HTMLImage | string The Image to use as the alpha mask. If you give a key it will try and find the Image in the Game.Cache.
- Source:
-
clear()
-
Clears the BitmapData.
- Source:
-
copyPixels(source, area, destX, destY)
-
Copies the pixels from the source image to this BitmapData based on the given area and destination.
Parameters:
Name Type Description source
HTMLImage | string The Image to draw. If you give a key it will try and find the Image in the Game.Cache.
area
Phaser.Rectangle The Rectangle region to copy from the source image.
destX
number The destination x coordinate to copy the image to.
destY
number The destination y coordinate to copy the image to.
- Source:
-
draw(source, destX, destY)
-
Draws the given image to this BitmapData at the coordinates specified. If you need to only draw a part of the image use BitmapData.copyPixels instead.
Parameters:
Name Type Description source
HTMLImage | string The Image to draw. If you give a key it will try and find the Image in the Game.Cache.
destX
number The destination x coordinate to draw the image to.
destY
number The destination y coordinate to draw the image to.
- Source:
-
getPixel(x, y) → {number}
-
Get the color of a specific pixel.
Parameters:
Name Type Description x
number The X coordinate of the pixel to get.
y
number The Y coordinate of the pixel to get.
- Source:
Returns:
A native color value integer (format: 0xRRGGBB)
- Type
- number
-
getPixel32(x, y) → {number}
-
Get the color of a specific pixel including its alpha value.
Parameters:
Name Type Description x
number The X coordinate of the pixel to get.
y
number The Y coordinate of the pixel to get.
- Source:
Returns:
A native color value integer (format: 0xAARRGGBB)
- Type
- number
-
getPixels(rect) → {array}
-
Gets all the pixels from the region specified by the given Rectangle object.
Parameters:
Name Type Description rect
Phaser.Rectangle The Rectangle region to get.
- Source:
Returns:
CanvasPixelArray.
- Type
- array
-
refreshBuffer()
-
- Source:
-
render()
-
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.
- Source:
-
resize()
-
Resizes the BitmapData.
- Source:
-
setPixel(x, y, red, green, blue)
-
Sets the color of the given pixel to the specified red, green and blue values.
Parameters:
Name Type Description x
number The X coordinate of the pixel to be set.
y
number The Y coordinate of the pixel to be set.
red
number The red color value (between 0 and 255)
green
number The green color value (between 0 and 255)
blue
number The blue color value (between 0 and 255)
- Source:
-
setPixel32(x, y, red, green, blue, alpha)
-
Sets the color of the given pixel to the specified red, green, blue and alpha values.
Parameters:
Name Type Description x
number The X coordinate of the pixel to be set.
y
number The Y coordinate of the pixel to be set.
red
number The red color value, between 0 and 0xFF (255).
green
number The green color value, between 0 and 0xFF (255).
blue
number The blue color value, between 0 and 0xFF (255).
alpha
number The alpha color value, between 0 and 0xFF (255).
- Source: