Class: BitmapData

Phaser. BitmapData

A BitmapData object contains a Canvas element to which you can draw anything you like via normal Canvas context operations. A single BitmapData can be used as the texture one or many Images/Sprites. So if you need to dynamically create a Sprite texture then they are a good choice.

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

Properties:
Name Type Description
baseTexture PIXI.BaseTexture

The PIXI.BaseTexture.

Source:

canvas

Properties:
Name Type Description
canvas HTMLCanvasElement

The canvas to which this BitmapData draws.

Source:

context

Properties:
Name Type Description
context CanvasRenderingContext2D

The 2d context of the canvas.

Source:

ctx

Properties:
Name Type Description
ctx CanvasRenderingContext2D

A reference to BitmapData.context.

Source:

dirty

Properties:
Name Type Description
dirty boolean

If dirty this BitmapData will be re-rendered.

Source:

game

Properties:
Name Type Description
game Phaser.Game

A reference to the currently running game.

Source:

height

Properties:
Name Type Description
height number

The height of the BitmapData in pixels.

Source:

imageData

Properties:
Name Type Description
imageData array

The canvas image data.

Source:

key

Properties:
Name Type Description
key string

The key of the BitmapData in the Cache, if stored there.

Source:

pixels

Properties:
Name Type Description
pixels UInt8Clamped

A reference to the context imageData buffer.

Source:

texture

Properties:
Name Type Description
texture PIXI.Texture

The PIXI.Texture.

Source:

textureFrame

Properties:
Name Type Description
textureFrame Phaser.Frame

The Frame this BitmapData uses for rendering.

Source:

type

Properties:
Name Type Description
type number

The const type of this object.

Source:

width

Properties:
Name Type Description
width number

The width of the BitmapData in pixels.

Source:

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:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Tue Apr 15 2014 02:52:23 GMT+0100 (BST) using the DocStrap template.