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.
function Bitmap()
Quick Reference
Setup & Creation 9
| initialize() | Sets up a new instance. |
| load() | Loads a image file. |
| _makeFontNameText() | Makes the font name text. |
| _createCanvas() | Creates the canvas. |
| _ensureCanvas() | Ensure canvas. |
| _createBaseTexture() | Creates the base texture. |
| _buildFramePng() | Build frame png. |
| _buildFrameGif() | Build frame gif. |
| _loadAnimationFrames() | Loads the animation frames. |
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) 7
| isReady() | Checks whether the bitmap is ready to render. |
| isError() | Checks whether a loading error has occurred. |
| _hasPngSignature() | Whether it has the png signature. |
| _isAnimatedImage() | Whether a url names a format whose frames the engine decodes itself. |
| 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 15
| 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. |
| _destroyCanvas() | Destroy canvas. |
| _startLoading() | Starts the loading. |
| _startDecrypting() | Starts the decrypting. |
| _dropPendingRequest() | Drop pending request. |
| _requestEncrypted() | Requests the encrypted. |
| _requestBytes() | Requests the bytes. |
| _startAnimation() | Starts the animation. |
| 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. |
| _callLoadListeners() | Call load listeners. |
Events, Commands & Input 5
| _onXhrLoad() | Called when xhr load happens. |
| _onImageBytes() | Called when image bytes happens. |
| _onEncryptedError() | Called when encrypted error happens. |
| _onLoad() | Called when load happens. |
| _onError() | Called when error happens. |
Updating & Drawing 12
| drawCircle() | Draws a bitmap in the shape of a circle. |
| drawText() | Draws the outline text to the bitmap. |
| _drawTextOutline() | Draws the text outline. |
| _drawTextBody() | Draws the text body. |
| paintLegacyGlyph() | Paint one source System colour cell through a monochrome glyph mask. |
| _drawLegacyPaletteRun() | Native legacy text draws each glyph's shadow and body before the next glyph. |
| _drawLegacyPaletteText() | Draws the legacy palette text. |
| _drawLegacyPixelText() | 2000/2003 used monochrome glyph masks. |
| _drawingContext() | The context for the ops in this file, without marking it lent. |
| _updateScaleMode() | Updates the scale mode each frame. |
| _updateAnimatedImage() | Updates the animated image each frame. |
| _renderAnimationFrame() | Composites one frame onto the canvas. |
Other 25
| 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. |
| _sweepStalledLoads() | Sweep stalled loads. |
| 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. |
| _touchUpload() | Touch upload. |
| _revokeObjectUrl() | Revoke object url. |
| _mimeType() | Mime type. |
| _crc32() | Crc32. |
| _asUint8() | As uint8. |
| _concatBytes() | Concat bytes. |
| _parseAnimation() | Splits an animated image into its frames, choosing a parser by url. |
| parseApng() | Splits an APNG into one standalone PNG per frame. |
| parseGif() | Splits an animated GIF into one standalone single-frame GIF per frame. |
| _animationHoldTime() | Animation hold time. |
| _advanceAnimation() | Advance animation. |
| 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 sourceBitmap.prototype.initialize(width, height)
Sets up a new instance. (Same as the RPG Maker MZ method of this name.)
load
static sourceBitmap.load(url, fallbackUrls)
Loads a image file.
Details
Loads a image file.
_makeFontNameText
method internal sourceBitmap.prototype._makeFontNameText()
Makes the font name text. (Same as the RPG Maker MZ method of this name.)
_createCanvas
method internal sourceBitmap.prototype._createCanvas(width, height)
Creates the canvas. (Same as the RPG Maker MZ method of this name.)
_ensureCanvas
method internal sourceBitmap.prototype._ensureCanvas()
Ensure canvas. (Same as the RPG Maker MZ method of this name.)
_createBaseTexture
method internal sourceBitmap.prototype._createBaseTexture(source)
Creates the base texture. (Same as the RPG Maker MZ method of this name.)
_buildFramePng
static internal sourceBitmap._buildFramePng(header, shared, frame)
Build frame png. (Same as the RPG Maker MZ method of this name.)
_buildFrameGif
static internal sourceBitmap._buildFrameGif(frame)
Build frame gif. (Same as the RPG Maker MZ method of this name.)
_loadAnimationFrames
method internal sourceBitmap.prototype._loadAnimationFrames(animation)
Loads the animation frames. (Same as the RPG Maker MZ method of this name.)
Getting Information
getPixel
method sourceBitmap.prototype.getPixel(x, y)
Returns pixel color at the specified point.
Details
Returns pixel color at the specified point.
getAlphaPixel
method sourceBitmap.prototype.getAlphaPixel(x, y)
Returns alpha pixel value at the specified point.
Details
Returns alpha pixel value at the specified point.
measureTextWidth
method sourceBitmap.prototype.measureTextWidth(text)
Returns the width of the specified text.
Details
Returns the width of the specified text.
textShadow
static sourceBitmap.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 sourceBitmap.prototype.isReady()
Checks whether the bitmap is ready to render.
Details
Checks whether the bitmap is ready to render.
isError
method sourceBitmap.prototype.isError()
Checks whether a loading error has occurred.
Details
Checks whether a loading error has occurred.
_hasPngSignature
static internal sourceBitmap._hasPngSignature(bytes)
Whether it has the png signature. (Same as the RPG Maker MZ method of this name.)
_isAnimatedImage
static internal sourceBitmap._isAnimatedImage(url)
Whether a url names a format whose frames the engine decodes itself.
Details
Whether a url names a format whose frames the engine decodes itself. Keyed on the extension rather than the file's contents: sniffing every image would cost a byte read per file the game loads.
hasApngAnimation
static sourceBitmap.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.
isAnimated
method sourceBitmap.prototype.isAnimated()
Whether this bitmap is playing a decoded animation.
Details
Whether this bitmap is playing a decoded animation.
isAnimationPaused
method sourceBitmap.prototype.isAnimationPaused()
Whether the animation is held.
Details
Whether the animation is held.
Actions
destroy
method sourceBitmap.prototype.destroy()
Destroys the bitmap.
clearRect
method sourceBitmap.prototype.clearRect(x, y, width, height)
Clears the specified rectangle.
Details
Clears the specified rectangle.
clear
method sourceBitmap.prototype.clear()
Clears the entire bitmap.
addLoadListener
method sourceBitmap.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.
_destroyCanvas
method internal sourceBitmap.prototype._destroyCanvas()
Destroy canvas. (Same as the RPG Maker MZ method of this name.)
_startLoading
method internal sourceBitmap.prototype._startLoading()
Starts the loading. (Same as the RPG Maker MZ method of this name.)
_startDecrypting
method internal sourceBitmap.prototype._startDecrypting()
Starts the decrypting. (Same as the RPG Maker MZ method of this name.)
_dropPendingRequest
method internal sourceBitmap.prototype._dropPendingRequest()
Drop pending request. (Same as the RPG Maker MZ method of this name.)
_requestEncrypted
method internal sourceBitmap.prototype._requestEncrypted(url)
Requests the encrypted. (Same as the RPG Maker MZ method of this name.)
_requestBytes
method internal sourceBitmap.prototype._requestBytes(url)
Requests the bytes. (Same as the RPG Maker MZ method of this name.)
_startAnimation
method internal sourceBitmap.prototype._startAnimation(animation, images)
Starts the animation. (Same as the RPG Maker MZ method of this name.)
pauseAnimation
method sourceBitmap.prototype.pauseAnimation()
Holds the animation on the frame it is showing.
playAnimation
method sourceBitmap.prototype.playAnimation()
Resumes a held animation from the frame it is showing.
setAnimationLoopCount
method sourceBitmap.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.
_callLoadListeners
method internal sourceBitmap.prototype._callLoadListeners()
Call load listeners. (Same as the RPG Maker MZ method of this name.)
Events, Commands & Input
_onXhrLoad
method internal sourceBitmap.prototype._onXhrLoad(xhr)
Called when xhr load happens. (Same as the RPG Maker MZ method of this name.)
_onImageBytes
method internal sourceBitmap.prototype._onImageBytes(arrayBuffer)
Called when image bytes happens. (Same as the RPG Maker MZ method of this name.)
_onEncryptedError
method internal sourceBitmap.prototype._onEncryptedError()
Called when encrypted error happens. (Same as the RPG Maker MZ method of this name.)
_onLoad
method internal sourceBitmap.prototype._onLoad()
Called when load happens. (Same as the RPG Maker MZ method of this name.)
_onError
method internal sourceBitmap.prototype._onError()
Called when error happens. (Same as the RPG Maker MZ method of this name.)
Updating & Drawing
drawCircle
method sourceBitmap.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.
drawText
method sourceBitmap.prototype.drawText(text, x, y, maxWidth, lineHeight, align)
Draws the outline text to the bitmap.
Details
Draws the outline text to the bitmap.
_drawTextOutline
method internal sourceBitmap.prototype._drawTextOutline(text, tx, ty, maxWidth)
Draws the text outline. (Same as the RPG Maker MZ method of this name.)
_drawTextBody
method internal sourceBitmap.prototype._drawTextBody(text, tx, ty, maxWidth)
Draws the text body. (Same as the RPG Maker MZ method of this name.)
paintLegacyGlyph
static sourceBitmap.paintLegacyGlyph(pixels, width, height, pad, ascent, paint, shadow)
Paint one source System colour cell through a monochrome glyph mask.
_drawLegacyPaletteRun
method internal sourceBitmap.prototype._drawLegacyPaletteRun(text, tx, ty)
Native legacy text draws each glyph's shadow and body before the next glyph.
_drawLegacyPaletteText
method internal sourceBitmap.prototype._drawLegacyPaletteText(text, tx, ty, paint, shadow, pairedBodyPaint)
Draws the legacy palette text. (Same as the RPG Maker MZ method of this name.)
_drawLegacyPixelText
method internal sourceBitmap.prototype._drawLegacyPixelText(text, tx, ty, color, outline = 0)
2000/2003 used monochrome glyph masks.
Details
2000/2003 used monochrome glyph masks. Nearest texture sampling cannot remove antialiasing already baked into a browser-rendered fallback font. Cache native-size, hard-edged masks for these projects only; modern text and legacy projects with Pixelated Rendering disabled retain canvas text.
_drawingContext
method internal sourceBitmap.prototype._drawingContext()
The context for the ops in this file, without marking it lent.
_updateScaleMode
method internal sourceBitmap.prototype._updateScaleMode()
Updates the scale mode each frame. (Same as the RPG Maker MZ method of this name.)
_updateAnimatedImage
method internal sourceBitmap.prototype._updateAnimatedImage()
Updates the animated image each frame. (Same as the RPG Maker MZ method of this name.)
_renderAnimationFrame
method internal sourceBitmap.prototype._renderAnimationFrame(index)
Composites one frame onto the canvas.
Details
Composites one frame onto the canvas. Deliberately does not upload: callers batch that, so a seek replaying N frames still costs one texture update.
Other
defaultOutlineWidth
static sourceBitmap.defaultOutlineWidth()
System.json advanced.textOutlineWidth (a 16 px game draws a 1 px shadow); 3 when the data is not loaded.
snap
static sourceBitmap.snap(stage)
Takes a snapshot of the game screen.
Details
Takes a snapshot of the game screen.
_sweepStalledLoads
static internal sourceBitmap._sweepStalledLoads()
Sweep stalled loads. (Same as the RPG Maker MZ method of this name.)
resize
method sourceBitmap.prototype.resize(width, height)
Resizes the bitmap.
Details
Resizes the bitmap.
blt
method sourceBitmap.prototype.blt(source, sx, sy, sw, sh, dx, dy, dw, dh)
Performs a block transfer.
Details
Performs a block transfer.
fillRect
method sourceBitmap.prototype.fillRect(x, y, width, height, color)
Fills the specified rectangle.
Details
Fills the specified rectangle.
fillAll
method sourceBitmap.prototype.fillAll(color)
Fills the entire bitmap.
Details
Fills the entire bitmap.
strokeRect
method sourceBitmap.prototype.strokeRect(x, y, width, height, color)
Draws the specified rectangular frame.
Details
Draws the specified rectangular frame.
retry
method sourceBitmap.prototype.retry()
Tries to load the image again.
pixelText
static sourceBitmap.pixelText()
System.json advanced.pixelatedRendering: text is placed on whole pixels.
legacyFontInfo
static sourceBitmap.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 sourceBitmap.fixedFontSize()
Fixed font size. (Same as the RPG Maker MZ method of this name.)
_touchUpload
method internal sourceBitmap.prototype._touchUpload(x, y, width, height)
Touch upload. (Same as the RPG Maker MZ method of this name.)
_revokeObjectUrl
method internal sourceBitmap.prototype._revokeObjectUrl()
Revoke object url. (Same as the RPG Maker MZ method of this name.)
_mimeType
static internal sourceBitmap._mimeType(url)
Mime type. (Same as the RPG Maker MZ method of this name.)
_crc32
static internal sourceBitmap._crc32(bytes)
Crc32. (Same as the RPG Maker MZ method of this name.)
_asUint8
static internal sourceBitmap._asUint8(source)
As uint8. (Same as the RPG Maker MZ method of this name.)
_concatBytes
static internal sourceBitmap._concatBytes(pieces)
Concat bytes. (Same as the RPG Maker MZ method of this name.)
_parseAnimation
static internal sourceBitmap._parseAnimation(url, source)
Splits an animated image into its frames, choosing a parser by url.
Details
Splits an animated image into its frames, choosing a parser by url.
parseApng
static sourceBitmap.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.
parseGif
static sourceBitmap.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.
_animationHoldTime
method internal sourceBitmap.prototype._animationHoldTime(index)
Animation hold time. (Same as the RPG Maker MZ method of this name.)
_advanceAnimation
method internal sourceBitmap.prototype._advanceAnimation()
Advance animation. (Same as the RPG Maker MZ method of this name.)
seekAnimation
method sourceBitmap.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.
restartAnimation
method sourceBitmap.prototype.restartAnimation()
Replays the animation from its first frame, loop count included.