Class: Bitmap

Bitmap

new Bitmap(width, height)

The basic object that represents an image.
NameTypeDescription
widthnumberThe width of the bitmap
heightnumberThe height of the bitmap

Members

baseTexturePIXI.BaseTexturereadonly

The base texture that holds the image

canvasHTMLCanvasElementreadonly

The bitmap canvas

contextCanvasRenderingContext2Dreadonly

The 2d context of the bitmap canvas

fontBoldboolean

Whether the font is bold.

fontFacestring

The face name of the font.

fontItalicboolean

Whether the font is italic.

fontSizenumber

The size of the font in pixels.

heightnumberreadonly

The height of the bitmap

imageHTMLImageElementreadonly

The bitmap image

outlineColorstring

The color of the outline of the text in CSS format.

outlineWidthnumber

The width of the outline of the text.

paintOpacitynumber

The opacity of the drawing object in the range (0, 255)

rectRectanglereadonly

The rectangle of the bitmap

smoothboolean

Whether smooth scaling is applied.

textColorstring

The color of the text in CSS format.

urlstringreadonly

The url of the image file

widthnumberreadonly

The width of the bitmap

Methods

addLoadListener(listner)

Adds a callback function that will be called when the bitmap is done loading
NameTypeDescription
listnerfunctionThe callback function

blt(source, sx, sy, sw, sh, dx, dy, dw, dh)

Performs a block transfer
NameTypeDefaultDescription
sourceBitmapThe bitmap to draw
sxnumberThe x coordinate in the source to start transfer from
synumberThe y coordinate in the source to start transfer from
swnumberThe width to use from the source image
shnumberThe height to use from the source image
dxnumberThe x coordinate in the destination
dynumberThe y coordinate in the destination
dwnumberswoptionalThe width to draw the image in the destination
dhnumbershoptionalThe height to draw the image in the destination
Clears the entire bitmap

clearRect(x, y, width, height)

Clears the specified rectangle
NameTypeDescription
xnumberThe x coordinate for the upper-left corner
ynumberThe y coordinate for the upper-left corner
widthnumberThe width of the rectangle to clear
heightnumberThe height of the rectangle to clear

destroy()

Destroys the bitmap

drawCircle(x, y, radius, color)

Draws a circle on the bitmap
NameTypeDescription
xnumberThe x coordinate based on the circle center
ynumberThe y coordinate based on the circle center
radiusnumberThe radius of the circle
colorstringThe color of the circle in CSS format

drawText(text, x, y, maxWidth, lineHeight, align)

Draws the given text to the bitmap
NameTypeDescription
textstringThe text that will be drawn
xnumberThe x coordinate for the left of the text
ynumberThe y coordinate for the top of the text
maxWidthnumberThe maximum allowed width of the text
lineHeightnumberThe height of the text line
alignstringThe alignment of the text

fillAll(color)

Fills the entire bitmap
NameTypeDescription
colorstringThe color of the rectangle in CSS format

fillRect(x, y, width, height, color)

Fills the specified rectangle
NameTypeDescription
xnumberThe x coordinate for the upper-left corner
ynumberThe y coordinate for the upper-left corner
widthnumberThe width of the rectangle to fill
heightnumberThe height of the rectangle to fill
colorstringThe color of the rectangle in CSS format

getAlphaPixel(x, y)string

Returns the alpha value of the pixel at the given x/y coordinates
NameTypeDescription
xnumberThe x coordinate of the pixel
ynumberThe y coordinate of the pixel
Returns:
TypeDescription
stringThe alpha value

getPixel(x, y)string

Returns the color in hex format of the pixel at the given x/y coordinates
NameTypeDescription
xnumberThe x coordinate of the pixel
ynumberThe y coordinate of the pixel
Returns:
TypeDescription
stringThe pixel color (hex format)

gradientFillRect(x, y, width, height, color1, color2, vertical)

Draws the rectangle with a gradient color fill
NameTypeDescription
xnumberThe x coordinate for the upper-left corner
ynumberThe y coordinate for the upper-left corner
widthnumberThe width of the rectangle
heightnumberThe height of the rectangle
color1stringThe gradient starting color
color2stringThe gradient ending color
verticalbooleanWhether the gradient should be drawn as vertical or not

initialize(width, height)

Initializes the bitmap object
NameTypeDescription
widthnumberThe width of the bitmap
heightnumberThe height of the bitmap

isError()boolean

Checks whether a loading error has occurred
Returns:
TypeDescription
booleanTrue if a loading error has occurred

isReady()boolean

Checks whether the bitmap is ready to render (it is done loading)
Returns:
TypeDescription
booleanTrue if the bitmap is ready to render

measureTextWidth(text)number

Gets the width of the given text
NameTypeDescription
textstringThe text to be measured
Returns:
TypeDescription
numberThe width of the text in pixels

resize(width, height)

Resizes the bitmap
NameTypeDescription
widthnumberThe new width of the bitmap
heightnumberThe new height of the bitmap
Tries to load the image again

strokeRect(x, y, width, height, color)

Draws the specified rectangular frame
NameTypeDescription
xnumberThe x coordinate for the upper-left corner
ynumberThe y coordinate for the upper-left corner
widthnumberThe width of the rectangle to fill
heightnumberThe height of the rectangle to fill
colorstringThe color of the rectangle in CSS format

Bitmap.load(url)Bitmapstatic

Loads an image file from the given url
NameTypeDescription
urlstringThe file path of the image file
Returns:
TypeDescription
BitmapThe created bitmap object

Bitmap.snap(stage)Bitmapstatic

Takes a snapshot of the game screen
NameTypeDescription
stageStageThe stage object
Returns:
TypeDescription
BitmapThe created bitmap object