Class in reactor_core.js

Bitmap

36 public functions in 6 groups · show internal (_) functions

Core runtime: data, input and the ReactorEvents feed.

Familiar territory. Bitmap keeps the RPG Maker MZ API, so existing MZ knowledge, tutorials and plugin code apply. Reactor's additions are marked with descriptions below.

The basic object that represents an image.

@class
@param
width number The width of the bitmap.
@param
height number The height of the bitmap.
function Bitmap()

Quick Reference

Setup & Creation 2

initialize() Sets up a new instance.
load() Loads a image file.

Getting Information 4

getPixel() Returns pixel color at the specified point.
getAlphaPixel() Returns alpha pixel value at the specified point.
measureTextWidth() Returns the width of the specified text.
textShadow() System.json advanced.rrTextShadow: text casts a sharp 1 px drop shadow instead of an outline, as 2000/2003 dr…

Checks (True / False) 5

isReady() Checks whether the bitmap is ready to render.
isError() Checks whether a loading error has occurred.
hasApngAnimation() Whether an image file carries APNG animation, i.e.
isAnimated() Whether this bitmap is playing a decoded animation.
isAnimationPaused() Whether the animation is held.

Actions 7

destroy() Destroys the bitmap.
clearRect() Clears the specified rectangle.
clear() Clears the entire bitmap.
addLoadListener() Adds a callback function that will be called when the bitmap is loaded.
pauseAnimation() Holds the animation on the frame it is showing.
playAnimation() Resumes a held animation from the frame it is showing.
setAnimationLoopCount() Overrides how many times the animation plays, ignoring the count the file asked for.

Updating & Drawing 3

drawCircle() Draws a bitmap in the shape of a circle.
drawText() Draws the outline text to the bitmap.
paintLegacyGlyph() Paint one source System colour cell through a monochrome glyph mask.

Other 15

defaultOutlineWidth() System.json advanced.textOutlineWidth (a 16 px game draws a 1 px shadow); 3 when the data is not loaded.
snap() Takes a snapshot of the game screen.
resize() Resizes the bitmap.
blt() Performs a block transfer.
fillRect() Fills the specified rectangle.
fillAll() Fills the entire bitmap.
strokeRect() Draws the specified rectangular frame.
retry() Tries to load the image again.
pixelText() System.json advanced.pixelatedRendering: text is placed on whole pixels.
legacyFontInfo() RPG Maker 2000/2003 (System.json rrLegacyWindows): every text is drawn at the font's own size (advanced.fontS…
fixedFontSize() Fixed font size.
parseApng() Splits an APNG into one standalone PNG per frame.
parseGif() Splits an animated GIF into one standalone single-frame GIF per frame.
seekAnimation() Jumps to a frame. Earlier frames are replayed rather than skipped, because a frame in either format is a diff…
restartAnimation() Replays the animation from its first frame, loop count included.

Setup & Creation

initialize

method source
Bitmap.prototype.initialize(width, height)

Sets up a new instance. (Same as the RPG Maker MZ method of this name.)

load

static source
Bitmap.load(url, fallbackUrls)

Loads a image file.

Details

Loads a image file.

@param
url string The image url of the texture.
@returns
Bitmap The new bitmap object.

Getting Information

getPixel

method source
Bitmap.prototype.getPixel(x, y)

Returns pixel color at the specified point.

Details

Returns pixel color at the specified point.

@param
x number The x coordinate of the pixel in the bitmap.
@param
y number The y coordinate of the pixel in the bitmap.
@returns
string The pixel color (hex format).

getAlphaPixel

method source
Bitmap.prototype.getAlphaPixel(x, y)

Returns alpha pixel value at the specified point.

Details

Returns alpha pixel value at the specified point.

@param
x number The x coordinate of the pixel in the bitmap.
@param
y number The y coordinate of the pixel in the bitmap.
@returns
string The alpha value.

measureTextWidth

method source
Bitmap.prototype.measureTextWidth(text)

Returns the width of the specified text.

Details

Returns the width of the specified text.

@param
text string The text to be measured.
@returns
number The width of the text in pixels.

textShadow

static source
Bitmap.textShadow()

System.json advanced.rrTextShadow: text casts a sharp 1 px drop shadow instead of an outline, as 2000/2003 drew it.

Checks (True / False)

isReady

method source
Bitmap.prototype.isReady()

Checks whether the bitmap is ready to render.

Details

Checks whether the bitmap is ready to render.

@returns
boolean True if the bitmap is ready to render.

isError

method source
Bitmap.prototype.isError()

Checks whether a loading error has occurred.

Details

Checks whether a loading error has occurred.

@returns
boolean True if a loading error has occurred.

hasApngAnimation

static source
Bitmap.hasApngAnimation(source)

Whether an image file carries APNG animation, i.e.

Details

Whether an image file carries APNG animation, i.e. an acTL chunk ahead of the first IDAT. A file with acTL after IDAT is malformed and reads as a plain PNG, which is what the specification asks for.

@param
source ArrayBuffer|Uint8Array The raw file bytes.
@returns
boolean True if the file is an animated PNG.

isAnimated

method source
Bitmap.prototype.isAnimated()

Whether this bitmap is playing a decoded animation.

Details

Whether this bitmap is playing a decoded animation.

@returns
boolean True while frames are being composited.

isAnimationPaused

method source
Bitmap.prototype.isAnimationPaused()

Whether the animation is held.

Details

Whether the animation is held.

@returns
boolean True if paused.

Actions

destroy

method source
Bitmap.prototype.destroy()

Destroys the bitmap.

clearRect

method source
Bitmap.prototype.clearRect(x, y, width, height)

Clears the specified rectangle.

Details

Clears the specified rectangle.

@param
x number The x coordinate for the upper-left corner.
@param
y number The y coordinate for the upper-left corner.
@param
width number The width of the rectangle to clear.
@param
height number The height of the rectangle to clear.

clear

method source
Bitmap.prototype.clear()

Clears the entire bitmap.

addLoadListener

method source
Bitmap.prototype.addLoadListener(listner)

Adds a callback function that will be called when the bitmap is loaded.

Details

Adds a callback function that will be called when the bitmap is loaded.

@param
listner function The callback function.

pauseAnimation

method source
Bitmap.prototype.pauseAnimation()

Holds the animation on the frame it is showing.

playAnimation

method source
Bitmap.prototype.playAnimation()

Resumes a held animation from the frame it is showing.

setAnimationLoopCount

method source
Bitmap.prototype.setAnimationLoopCount(count)

Overrides how many times the animation plays, ignoring the count the file asked for.

Details

Overrides how many times the animation plays, ignoring the count the file asked for. A GIF with no loop block asks to be shown once; this is how a plugin makes one loop forever.

@param
count number Passes to play; 0 loops forever.

Updating & Drawing

drawCircle

method source
Bitmap.prototype.drawCircle(x, y, radius, color)

Draws a bitmap in the shape of a circle.

Details

Draws a bitmap in the shape of a circle.

@param
x number The x coordinate based on the circle center.
@param
y number The y coordinate based on the circle center.
@param
radius number The radius of the circle.
@param
color string The color of the circle in CSS format.

drawText

method source
Bitmap.prototype.drawText(text, x, y, maxWidth, lineHeight, align)

Draws the outline text to the bitmap.

Details

Draws the outline text to the bitmap.

@param
text string The text that will be drawn.
@param
x number The x coordinate for the left of the text.
@param
y number The y coordinate for the top of the text.
@param
maxWidth number The maximum allowed width of the text.
@param
lineHeight number The height of the text line.
@param
align string The alignment of the text.

paintLegacyGlyph

static source
Bitmap.paintLegacyGlyph(pixels, width, height, pad, ascent, paint, shadow)

Paint one source System colour cell through a monochrome glyph mask.

Other

defaultOutlineWidth

static source
Bitmap.defaultOutlineWidth()

System.json advanced.textOutlineWidth (a 16 px game draws a 1 px shadow); 3 when the data is not loaded.

snap

static source
Bitmap.snap(stage)

Takes a snapshot of the game screen.

Details

Takes a snapshot of the game screen.

@param
stage Stage The stage object.
@returns
Bitmap The new bitmap object.

resize

method source
Bitmap.prototype.resize(width, height)

Resizes the bitmap.

Details

Resizes the bitmap.

@param
width number The new width of the bitmap.
@param
height number The new height of the bitmap.

blt

method source
Bitmap.prototype.blt(source, sx, sy, sw, sh, dx, dy, dw, dh)

Performs a block transfer.

Details

Performs a block transfer.

@param
source Bitmap The bitmap to draw.
@param
sx number The x coordinate in the source.
@param
sy number The y coordinate in the source.
@param
sw number The width of the source image.
@param
sh number The height of the source image.
@param
dx number The x coordinate in the destination.
@param
dy number The y coordinate in the destination.
@param
[dw=sw] number The width to draw the image in the destination.
@param
[dh=sh] number The height to draw the image in the destination.

fillRect

method source
Bitmap.prototype.fillRect(x, y, width, height, color)

Fills the specified rectangle.

Details

Fills the specified rectangle.

@param
x number The x coordinate for the upper-left corner.
@param
y number The y coordinate for the upper-left corner.
@param
width number The width of the rectangle to fill.
@param
height number The height of the rectangle to fill.
@param
color string The color of the rectangle in CSS format.

fillAll

method source
Bitmap.prototype.fillAll(color)

Fills the entire bitmap.

Details

Fills the entire bitmap.

@param
color string The color of the rectangle in CSS format.

strokeRect

method source
Bitmap.prototype.strokeRect(x, y, width, height, color)

Draws the specified rectangular frame.

Details

Draws the specified rectangular frame.

@param
x number The x coordinate for the upper-left corner.
@param
y number The y coordinate for the upper-left corner.
@param
width number The width of the rectangle to fill.
@param
height number The height of the rectangle to fill.
@param
color string The color of the rectangle in CSS format.

retry

method source
Bitmap.prototype.retry()

Tries to load the image again.

pixelText

static source
Bitmap.pixelText()

System.json advanced.pixelatedRendering: text is placed on whole pixels.

legacyFontInfo

static source
Bitmap.legacyFontInfo()

RPG Maker 2000/2003 (System.json rrLegacyWindows): every text is drawn at the font's own size (advanced.fontSize) and at its natural width, never squeezed; a pixel font at any other size blurs.

fixedFontSize

static source
Bitmap.fixedFontSize()

Fixed font size. (Same as the RPG Maker MZ method of this name.)

parseApng

static source
Bitmap.parseApng(source)

Splits an APNG into one standalone PNG per frame.

Details

Splits an APNG into one standalone PNG per frame.

Returns null for anything that is not a usable animation -- not a PNG, no acTL, a single frame, a frame with no data -- so callers fall back to the ordinary static path rather than failing on a file the engine can still show.

@param
source ArrayBuffer|Uint8Array The raw file bytes.
@returns
?object {width, height, playCount, mimeType, frames}, playCount 0 meaning loop forever; each frame is {x, y, width, height, delayMs, disposeOp, blendOp, bytes} where bytes is a complete one-frame file.

parseGif

static source
Bitmap.parseGif(source)

Splits an animated GIF into one standalone single-frame GIF per frame.

Details

Splits an animated GIF into one standalone single-frame GIF per frame.

The LZW data is copied across byte for byte, interlace flag included, so no decompression happens here -- each frame is handed back to the browser as a tiny GIF of its own. Returns null for a still GIF or anything unreadable, so callers fall back to the ordinary static path.

@param
source ArrayBuffer|Uint8Array The raw file bytes.
@returns
?object The animation, shaped exactly as parseApng returns.

seekAnimation

method source
Bitmap.prototype.seekAnimation(index)

Jumps to a frame. Earlier frames are replayed rather than skipped, because a frame in either format is a difference against the ones before it, not a whole picture.

Details

Jumps to a frame. Earlier frames are replayed rather than skipped, because a frame in either format is a difference against the ones before it, not a whole picture.

@param
index number The frame to show.

restartAnimation

method source
Bitmap.prototype.restartAnimation()

Replays the animation from its first frame, loop count included.