Class in reactor_core.js

Graphics

75 functions in 6 groups · hide internal

Core runtime: data, input and the ReactorEvents feed.

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

The static class that carries out graphics processing.

@namespace
function Graphics()

Quick Reference

Setup & Creation 11

initialize() Initializes the graphics system.
_createAllElements() Creates the all elements.
_makeErrorHtml() Makes the error html.
_createErrorPrinter() Creates the error printer.
_createCanvas() Creates the canvas.
_createLoadingSpinner() Creates the loading spinner.
_createFPSCounter() Creates the fps counter.
_setupEventHandlers() Setup event handlers.
_createPixiApp() Creates the pixi app.
_setupPixi() Setup pixi.
_createEffekseerContext() Creates the effekseer context.

Checks (True / False) 4

isInsideCanvas() Checks whether the specified point is inside the game canvas area.
_canRender() Whether it can render.
isUpscaled() Whether the canvas is shown larger than its backing store.
_isFullScreen() Whether it is full screen.

Actions 17

setTickHandler() Register a handler for tick events.
startGameLoop() Starts the game loop.
stopGameLoop() Stops the game loop.
setStage() Sets the stage to be rendered.
startLoading() Shows the loading spinner.
endLoading() Erases the loading spinner.
showRetryButton() Displays a button to try to reload resources.
showScreen() Shows the game screen.
hideScreen() Hides the game screen.
requestRedraw() Draw the composite on the next refresh, update or not.
_applyUpscaleFilter() Give an on-screen canvas the enlargement filter in use, or none when it is not enlarged.
showEffekseerOverlay() Show the Effekseer overlay only while it carries screen effects.
_disableContextMenu() Disables the context menu.
_applyCanvasFilter() Applies the canvas filter.
_clearCanvasFilter() Clears the canvas filter.
_requestFullScreen() Requests the full screen.
_restoreEffekseerContext() The overlay's context came back after a loss: effects loaded into the old one are gone with it, so a new Effe…

Events, Commands & Input 4

_onTick() Called when tick happens.
_onWindowResize() Called when window resize happens.
_onKeyDown() Called when key down happens.
_listenEffekseerStateResets() Listen effekseer state resets.

Updating & Drawing 8

_updateAllElements() Updates the all elements each frame.
_updateReactor3DCanvas() Keep the 3D canvas the same size and place as the game canvas.
_updateRealScale() Updates the real scale each frame.
_updateErrorPrinter() Updates the error printer each frame.
_updateCanvas() Updates the canvas each frame.
_updateEffekseerCanvas() Updates the effekseer canvas each frame.
_updateVideo() Updates the video each frame.
rendererModeName() "WebGL", "WebGPU", or "Canvas" for a PIXI renderer, or "" when it cannot be told.

Other 31

printError() Displays the error text to the screen.
eraseError() Erases the loading error text.
pageToCanvasX() Converts an x coordinate on the page to the corresponding x coordinate on the canvas area.
pageToCanvasY() Converts a y coordinate on the page to the corresponding y coordinate on the canvas area.
resize() Changes the size of the game screen.
_watchTextureSources() Count texture sources taking new pixels (update()): none of them touches the sprite showing it.
_stageWork() The render work the stage has queued, as two numbers that only grow between composites: its render groups, an…
_groupWork() One render group's share of _stageWork and its child groups' (a method: this runs twice a refresh).
_frameChanged() Whether this refresh draws: updates is what the tick handler returned.
_noteComposite() What the composite just drawn left behind, for the next refresh to compare with.
realClockDelta() Real clock delta.
_mustComposite() A composite owed whatever the pacing says: the first, a new stage, or one asked for.
canvasPixelRatio() Backing-store scale for the game canvas: how many physical pixels back one game pixel on screen.
displayPixelRatio() Screen pixels per CSS pixel, 1 when the browser does not say.
upscaleFilterInUse() The filter the setting resolves to right now.
scalingReport() One line saying how the frame reaches the screen right now: the canvas store and its ratio, the 3D pass size…
_sampleGpuTier() Sample gpu tier.
_stretchWidth() Stretch width.
_stretchHeight() Stretch height.
_defaultStretchMode() Default stretch mode.
_centerElement() Center element.
_switchFPSCounter() Switch fps counter.
_switchStretchMode() Switch stretch mode.
_switchFullScreen() Switch full screen.
_cancelFullScreen() Cancel full screen.
blitSceneBehindEffects() Draw the composited scene — the 3D canvas when a map renders in 3D, then the game canvas — into the Effekseer…
rearmEffekseerState() Make the next Effekseer draw read back and restore the context's GL state.
settleEffekseerState() After endDraw(): the restoring draw has happened, stop paying for it.
FPSCounter() Fps counter.
graphicsDeviceName() The graphics device's name, short ("RTX 5070", "SwiftShader"), read once; "" when it will not say.
graphicsBackendName() How the browser reaches the graphics device, as its renderer string says ("Direct3D 11", "Direct3D 11 on 12",…

Setup & Creation

initialize

static source
Graphics.initialize()

Initializes the graphics system.

Details

Initializes the graphics system.

@returns
boolean True if the graphics system is available.

_createAllElements

static internal source
Graphics._createAllElements()

Creates the all elements. (Same as the RPG Maker MZ method of this name.)

_makeErrorHtml

static internal source
Graphics._makeErrorHtml(name, message /*, error*/)

Makes the error html. (Same as the RPG Maker MZ method of this name.)

_createErrorPrinter

static internal source
Graphics._createErrorPrinter()

Creates the error printer. (Same as the RPG Maker MZ method of this name.)

_createCanvas

static internal source
Graphics._createCanvas()

Creates the canvas. (Same as the RPG Maker MZ method of this name.)

_createLoadingSpinner

static internal source
Graphics._createLoadingSpinner()

Creates the loading spinner. (Same as the RPG Maker MZ method of this name.)

_createFPSCounter

static internal source
Graphics._createFPSCounter()

Creates the fps counter. (Same as the RPG Maker MZ method of this name.)

_setupEventHandlers

static internal source
Graphics._setupEventHandlers()

Setup event handlers. (Same as the RPG Maker MZ method of this name.)

_createPixiApp

static internal source
Graphics._createPixiApp()

Creates the pixi app. (Same as the RPG Maker MZ method of this name.)

_setupPixi

static internal source
Graphics._setupPixi()

Setup pixi. (Same as the RPG Maker MZ method of this name.)

_createEffekseerContext

static internal source
Graphics._createEffekseerContext()

Creates the effekseer context. (Same as the RPG Maker MZ method of this name.)

Checks (True / False)

isInsideCanvas

static source
Graphics.isInsideCanvas(x, y)

Checks whether the specified point is inside the game canvas area.

Details

Checks whether the specified point is inside the game canvas area.

@param
x number The x coordinate on the canvas area.
@param
y number The y coordinate on the canvas area.
@returns
boolean True if the specified point is inside the game canvas area.

_canRender

static internal source
Graphics._canRender()

Whether it can render. (Same as the RPG Maker MZ method of this name.)

isUpscaled

static source
Graphics.isUpscaled()

Whether the canvas is shown larger than its backing store.

_isFullScreen

static internal source
Graphics._isFullScreen()

Whether it is full screen. (Same as the RPG Maker MZ method of this name.)

Actions

setTickHandler

static source
Graphics.setTickHandler(handler)

Register a handler for tick events.

Details

Register a handler for tick events.

@param
handler function The listener function to be added for updates.

startGameLoop

static source
Graphics.startGameLoop()

Starts the game loop.

stopGameLoop

static source
Graphics.stopGameLoop()

Stops the game loop.

setStage

static source
Graphics.setStage(stage)

Sets the stage to be rendered.

Details

Sets the stage to be rendered.

@param
stage Stage The stage object to be rendered.

startLoading

static source
Graphics.startLoading()

Shows the loading spinner.

endLoading

static source
Graphics.endLoading()

Erases the loading spinner.

Details

Erases the loading spinner.

@returns
boolean True if the loading spinner was active.

showRetryButton

static source
Graphics.showRetryButton(retry)

Displays a button to try to reload resources.

Details

Displays a button to try to reload resources.

@param
retry function The callback function to be called when the button is pressed.

showScreen

static source
Graphics.showScreen()

Shows the game screen.

hideScreen

static source
Graphics.hideScreen()

Hides the game screen.

requestRedraw

static source
Graphics.requestRedraw()

Draw the composite on the next refresh, update or not.

_applyUpscaleFilter

static internal source
Graphics._applyUpscaleFilter(element)

Give an on-screen canvas the enlargement filter in use, or none when it is not enlarged.

showEffekseerOverlay

static source
Graphics.showEffekseerOverlay(visible)

Show the Effekseer overlay only while it carries screen effects.

Details

Show the Effekseer overlay only while it carries screen effects. A hidden canvas still draws into its buffer (the in-scene effects are drawn there and copied out), but the compositor stops blending a full-screen transparent layer over the game every frame. Only a change touches the style.

_disableContextMenu

static internal source
Graphics._disableContextMenu()

Disables the context menu. (Same as the RPG Maker MZ method of this name.)

_applyCanvasFilter

static internal source
Graphics._applyCanvasFilter()

Applies the canvas filter. (Same as the RPG Maker MZ method of this name.)

_clearCanvasFilter

static internal source
Graphics._clearCanvasFilter()

Clears the canvas filter. (Same as the RPG Maker MZ method of this name.)

_requestFullScreen

static internal source
Graphics._requestFullScreen()

Requests the full screen. (Same as the RPG Maker MZ method of this name.)

_restoreEffekseerContext

static internal source
Graphics._restoreEffekseerContext()

The overlay's context came back after a loss: effects loaded into the old one are gone with it, so a new Effekseer context starts and every effect loads again on its next play.

Details

The overlay's context came back after a loss: effects loaded into the old one are gone with it, so a new Effekseer context starts and every effect loads again on its next play. Effects playing at the loss end there.

Events, Commands & Input

_onTick

static internal source
Graphics._onTick(deltaTime)

Called when tick happens. (Same as the RPG Maker MZ method of this name.)

_onWindowResize

static internal source
Graphics._onWindowResize()

Called when window resize happens. (Same as the RPG Maker MZ method of this name.)

_onKeyDown

static internal source
Graphics._onKeyDown(event)

Called when key down happens. (Same as the RPG Maker MZ method of this name.)

_listenEffekseerStateResets

static internal source
Graphics._listenEffekseerStateResets()

Listen effekseer state resets. (Same as the RPG Maker MZ method of this name.)

Updating & Drawing

_updateAllElements

static internal source
Graphics._updateAllElements()

Updates the all elements each frame. (Same as the RPG Maker MZ method of this name.)

_updateReactor3DCanvas

static internal source
Graphics._updateReactor3DCanvas()

Keep the 3D canvas the same size and place as the game canvas.

Details

Keep the 3D canvas the same size and place as the game canvas.

It is a sibling of the game canvas rather than one of Graphics' own elements, so it was missed whenever the window changed: going fullscreen scaled the game canvas up and left the 3D one at its old size, drawing the world as a small rectangle in the middle of a black screen.

_updateRealScale

static internal source
Graphics._updateRealScale()

Updates the real scale each frame. (Same as the RPG Maker MZ method of this name.)

_updateErrorPrinter

static internal source
Graphics._updateErrorPrinter()

Updates the error printer each frame. (Same as the RPG Maker MZ method of this name.)

_updateCanvas

static internal source
Graphics._updateCanvas()

Updates the canvas each frame. (Same as the RPG Maker MZ method of this name.)

_updateEffekseerCanvas

static internal source
Graphics._updateEffekseerCanvas()

Updates the effekseer canvas each frame. (Same as the RPG Maker MZ method of this name.)

_updateVideo

static internal source
Graphics._updateVideo()

Updates the video each frame. (Same as the RPG Maker MZ method of this name.)

rendererModeName

static source
Graphics.rendererModeName(renderer)

"WebGL", "WebGPU", or "Canvas" for a PIXI renderer, or "" when it cannot be told.

Details

"WebGL", "WebGPU", or "Canvas" for a PIXI renderer, or "" when it cannot be told. Polymorphic across PIXI versions: v8 renderers carry a name ("webgl"/"webgpu") and RendererType (1 WebGL, 2 WebGPU, 4 Canvas), v5-v7 use PIXI.RENDERER_TYPE (1 WebGL, 2 Canvas) — the numbers collide, so the string is preferred and the enum is read from whichever PIXI is loaded.

Other

printError

static source
Graphics.printError(name, message, error = null)

Displays the error text to the screen.

Details

Displays the error text to the screen.

@param
name string The name of the error.
@param
message string The message of the error.
@param
[error] Error The error object.

eraseError

static source
Graphics.eraseError()

Erases the loading error text.

pageToCanvasX

static source
Graphics.pageToCanvasX(x)

Converts an x coordinate on the page to the corresponding x coordinate on the canvas area.

Details

Converts an x coordinate on the page to the corresponding x coordinate on the canvas area.

@param
x number The x coordinate on the page to be converted.
@returns
number The x coordinate on the canvas area.

pageToCanvasY

static source
Graphics.pageToCanvasY(y)

Converts a y coordinate on the page to the corresponding y coordinate on the canvas area.

Details

Converts a y coordinate on the page to the corresponding y coordinate on the canvas area.

@param
y number The y coordinate on the page to be converted.
@returns
number The y coordinate on the canvas area.

resize

static source
Graphics.resize(width, height)

Changes the size of the game screen.

Details

Changes the size of the game screen.

@param
width number The width of the game screen.
@param
height number The height of the game screen.

_watchTextureSources

static internal source
Graphics._watchTextureSources()

Count texture sources taking new pixels (update()): none of them touches the sprite showing it.

_stageWork

static internal source
Graphics._stageWork(stage, into)

The render work the stage has queued, as two numbers that only grow between composites: its render groups, and every group's pending transform, view and structure updates (PIXI 8 queues each change there, and a composite consumes the queues).

Details

The render work the stage has queued, as two numbers that only grow between composites: its render groups, and every group's pending transform, view and structure updates (PIXI 8 queues each change there, and a composite consumes the queues). Null where the stage has no render group to read.

_groupWork

static internal source
Graphics._groupWork(group, into)

One render group's share of _stageWork and its child groups' (a method: this runs twice a refresh).

_frameChanged

static internal source
Graphics._frameChanged(updates)

Whether this refresh draws: updates is what the tick handler returned.

_noteComposite

static internal source
Graphics._noteComposite()

What the composite just drawn left behind, for the next refresh to compare with.

realClockDelta

static source
Graphics.realClockDelta(tickerDelta)

Real clock delta. (Same as the RPG Maker MZ method of this name.)

_mustComposite

static internal source
Graphics._mustComposite()

A composite owed whatever the pacing says: the first, a new stage, or one asked for.

canvasPixelRatio

static source
Graphics.canvasPixelRatio()

Backing-store scale for the game canvas: how many physical pixels back one game pixel on screen.

Details

Backing-store scale for the game canvas: how many physical pixels back one game pixel on screen. Fullscreen used to stretch the finished frame with the browser's bilinear filter — a blur layer over the whole game. Rendering the backing store at the on-screen size instead leaves nothing to stretch: 3D geometry comes out native-sharp while UI bitmaps (windows, text, pictures) still enlarge through the GPU's smooth sampling and look exactly as soft as before. 1 when the frame is not enlarged — shrinking keeps a 1:1 store — and capped so a video wall cannot demand an enormous framebuffer.

displayPixelRatio

static source
Graphics.displayPixelRatio()

Screen pixels per CSS pixel, 1 when the browser does not say.

upscaleFilterInUse

static source
Graphics.upscaleFilterInUse()

The filter the setting resolves to right now.

scalingReport

static source
Graphics.scalingReport()

One line saying how the frame reaches the screen right now: the canvas store and its ratio, the 3D pass size and its filter, the display scale and the GPU tier.

Details

One line saying how the frame reaches the screen right now: the canvas store and its ratio, the 3D pass size and its filter, the display scale and the GPU tier. Logged at debug level whenever it changes (a resize, F4), so a report of "it looks blurry" can carry the numbers.

_sampleGpuTier

static internal source
Graphics._sampleGpuTier(renderer)

Sample gpu tier. (Same as the RPG Maker MZ method of this name.)

_stretchWidth

static internal source
Graphics._stretchWidth()

Stretch width. (Same as the RPG Maker MZ method of this name.)

_stretchHeight

static internal source
Graphics._stretchHeight()

Stretch height. (Same as the RPG Maker MZ method of this name.)

_defaultStretchMode

static internal source
Graphics._defaultStretchMode()

Default stretch mode. (Same as the RPG Maker MZ method of this name.)

_centerElement

static internal source
Graphics._centerElement(element)

Center element. (Same as the RPG Maker MZ method of this name.)

_switchFPSCounter

static internal source
Graphics._switchFPSCounter()

Switch fps counter. (Same as the RPG Maker MZ method of this name.)

_switchStretchMode

static internal source
Graphics._switchStretchMode()

Switch stretch mode. (Same as the RPG Maker MZ method of this name.)

_switchFullScreen

static internal source
Graphics._switchFullScreen()

Switch full screen. (Same as the RPG Maker MZ method of this name.)

_cancelFullScreen

static internal source
Graphics._cancelFullScreen()

Cancel full screen. (Same as the RPG Maker MZ method of this name.)

blitSceneBehindEffects

static source
Graphics.blitSceneBehindEffects()

Draw the composited scene — the 3D canvas when a map renders in 3D, then the game canvas — into the Effekseer overlay's framebuffer.

Details

Draw the composited scene — the 3D canvas when a map renders in 3D, then the game canvas — into the Effekseer overlay's framebuffer. Effects with distortion or darkening layers sample a captured background; on its own transparent overlay canvas that background is empty, so those layers rendered as solid black. The scene is blitted, captured into Effekseer's background texture, and cleared away again before the effects draw.

rearmEffekseerState

static source
Graphics.rearmEffekseerState()

Make the next Effekseer draw read back and restore the context's GL state.

settleEffekseerState

static source
Graphics.settleEffekseerState()

After endDraw(): the restoring draw has happened, stop paying for it.

FPSCounter

static source
Graphics.FPSCounter()

Fps counter. (Same as the RPG Maker MZ method of this name.)

graphicsDeviceName

static source
Graphics.graphicsDeviceName(renderer)

The graphics device's name, short ("RTX 5070", "SwiftShader"), read once; "" when it will not say.

graphicsBackendName

static source
Graphics.graphicsBackendName()

How the browser reaches the graphics device, as its renderer string says ("Direct3D 11", "Direct3D 11 on 12", "OpenGL", "Vulkan", "Metal"); "" where it does not say or draws in software.

Details

How the browser reaches the graphics device, as its renderer string says ("Direct3D 11", "Direct3D 11 on 12", "OpenGL", "Vulkan", "Metal"); "" where it does not say or draws in software. Read after graphicsDeviceName.