Skip to content
pixi-silk
GitHub repository
Function

renderOnDemand

import { renderOnDemand } from 'pixi-silk';
function renderOnDemand(app: Application, options?: RenderOnDemandOptions): FrameGate;

Renders a frame only when something asks for it. The ticker keeps running, so layout, springs and game logic go on, but Pixi draws nothing on frames where nothing changed, and the canvas keeps showing the last frame.

A frame is drawn after invalidate() or requestFrame(), and while a hold() is open. A resize and input on the canvas draw one too.

pixi-silk asks on its own: a SilkGraphics when it is redrawn, the pixi-silk/ui widgets while they animate, and a BlockSurface when it paints.

Anything else that changes needs a call. Moving or fading a display object (x, alpha), a Pixi Text or Graphics, reels, a Spine skeleton or a video: call invalidate() after the change, or hold() while it plays. One gate per page: a second call makes a new gate, and the first one stops answering requestFrame.

Parameters#

ParameterType
appApplication
optionsRenderOnDemandOptions

Returns#

FrameGate

Example#

import { renderOnDemand } from 'pixi-silk';

const gate = renderOnDemand(app);
// while the reels spin
const release = gate.hold();
// when they stop
release();