Constructs a new Renderer instance
Renderer settings
Optionaltarget: string | HTMLElementElement ID or HTMLElement to insert the canvas into
Sets the target FPS for the global render loop
The target FPS to set for the global render loop. Set to 0 or a negative value to disable throttling.
Cleanup textures that are not being used
This can be used to free up GFX memory used by textures that are no longer being displayed.
This routine is also called automatically when the memory used by textures exceeds the critical threshold on frame generation OR when the renderer is idle and the memory used by textures exceeds the target threshold.
NOTE: This is a heavy operation and should be used sparingly.
NOTE2: This will not cleanup textures that are currently being displayed.
NOTE3: This will not cleanup textures that are marked as preventCleanup.
NOTE4: This has nothing to do with the garbage collection of JavaScript.
Clear all listeners for the given event names by setting their array length to 0, WITHOUT deleting the keys. This keeps the eventListeners object in V8's fast-properties mode and avoids re-allocating the arrays on the next on() call. Use this for objects with a known fixed set of event names (e.g. CoreAnimation, CoreAnimationController).
Only writes arr.length = 0 when the array is non-empty -- skips the write (and the write barrier on old-gen objects) when already empty, which is the common case after unregisterAnimation() has removed all listeners.
Close and destroy the renderer, releasing all resources.
This method performs a full teardown of the renderer:
Create a new scene graph node
A node is the main graphical building block of the Renderer scene graph. It can be a container for other nodes, or it can be a leaf node that renders a solid color, gradient, image, or specific texture, using a specific shader.
To create a text node, see createTextNode.
See CoreNode for more details.
Create a new shader controller for a shader type
Optionalprops: OptionalShaderProps<T>Create a new scene graph text node
A text node is the second graphical building block of the Renderer scene graph. It renders text using a specific text renderer that is automatically chosen based on the font requested and what type of fonts are installed into an app.
See ITextNode for more details.
Create a new texture reference
Optionaldata: anyCheck whether this emitter has any listeners registered.
Optionalevent: stringOptional event name. When provided, checks only that event. When omitted, checks all events.
true if at least one listener is registered.
Optionallistener: EventListenerRegister an active animation with the renderer.
This increments a global animation counter shared by both the internal animation engine and external animation libraries. While the counter is above zero, the renderer throttles texture uploads (configurable via the RendererMainSettings.maxTextureUploadsDuringAnimation setting, which defaults to one per frame) to preserve the frame budget.
Call unregisterAnimation when the animation completes, is cancelled, or is otherwise no longer driving per-frame updates.
The renderer's own INode.animate method handles this automatically. This API is intended for external animation libraries such as AnimeJS, GSAP, or custom tween loops.
// AnimeJS integration
import anime from 'animejs';
anime({
targets: myProps,
x: 500,
duration: 1000,
begin: () => renderer.registerAnimation(),
complete: () => renderer.unregisterAnimation(),
update: () => { node.x = myProps.x; },
});
// For AnimeJS timelines, use timeline-level hooks:
const tl = anime.timeline({
begin: () => renderer.registerAnimation(),
complete: () => renderer.unregisterAnimation(),
});
tl.add({ targets: node, x: 100, duration: 500 });
tl.add({ targets: node, y: 200, duration: 500 });
Sets the clear color for the stage.
The color to set as the clear color.
Unregister a previously registered animation.
Decrements the global animation counter. When the counter reaches zero, the renderer resumes full-budget texture processing (only limited by the RendererMainSettings.textureProcessingTimeLimit).
Must be called exactly once for each corresponding registerAnimation call.
The Renderer Main API
Remarks
This is the primary class used to configure and operate the Renderer.
It is used to create and destroy Nodes, as well as Texture and Shader references.
Example:
Event Handling
Listen to events using the standard EventEmitter API:
See
Fires
RendererMain#fpsUpdate
Fires
RendererMain#frameTick
Fires
RendererMain#quadsUpdate
Fires
RendererMain#idle
Fires
RendererMain#criticalCleanup
Fires
RendererMain#criticalCleanupFailed