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:

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.

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:

clear()

Clears the BitmapData.

Source:

getPixel(x, y) → {number}

Get a 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 a color of a specific pixel (including 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}

Get pixels in array in a specific Rectangle.

Parameters:
Name Type Description
rect Rectangle

The specific Rectangle.

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 Wed Feb 19 2014 05:26:22 GMT-0000 (GMT) using the DocStrap template.