Next2D Player is a high-performance 2D rendering engine using WebGL/WebGPU. It provides Flash Player-like functionality on the web, supporting vector graphics, Tween animations, text, audio, video, and more.
An overview of the pipeline that enables Next2D Player’s high-speed rendering.
flowchart TB
%% Main Drawing Flow Chart
subgraph MainFlow["Drawing Flow Chart - Main Rendering Pipeline"]
direction TB
subgraph Inputs["Display Objects"]
Shape["Shape<br/>(Bitmap/Vector)"]
TextField["TextField<br/>(canvas2d)"]
Video["Video Element"]
end
Shape --> MaskCheck
TextField --> MaskCheck
Video --> MaskCheck
MaskCheck{"mask<br/>rendering?"}
MaskCheck -->|YES| DirectRender["Direct Rendering"]
DirectRender -->|drawArrays| FinalRender
MaskCheck -->|NO| CacheCheck1{"cache<br/>exists?"}
CacheCheck1 -->|NO| TextureAtlas["Texture Atlas<br/>(Binary Tree Packing)"]
TextureAtlas --> Coordinates
CacheCheck1 -->|YES| Coordinates["Coordinates DB<br/>(x, y, w, h)"]
Coordinates --> FilterBlendCheck{"filter or<br/>blend?"}
FilterBlendCheck -->|NO| MainArrays
FilterBlendCheck -->|YES| NeedCache{"cache<br/>exists?"}
NeedCache -->|NO| CacheRender["Render to Cache"]
CacheRender --> TextureCache
NeedCache -->|YES| TextureCache["Texture Cache"]
TextureCache -->|drawArrays| FinalRender
MainArrays["Instanced Arrays<br/>━━━━━━━━━━━━━━━<br/>matrix<br/>colorTransform<br/>Coordinates<br/>━━━━━━━━━━━━━━━<br/><b>Batch Rendering</b>"]
MainArrays -->|drawArraysInstanced<br/><b>Multiple objects in one call</b>| FinalRender["Final Rendering"]
FinalRender -->|60fps| MainFramebuffer["Main Framebuffer<br/>(Display)"]
end
%% Branch Flow for Filter/Blend/Mask
subgraph BranchFlow["Filter/Blend/Mask - Branch Processing"]
direction TB
subgraph FilterInputs["Display Objects"]
Shape2["Shape<br/>(Bitmap/Vector)"]
TextField2["TextField<br/>(canvas2d)"]
Video2["Video Element"]
end
Shape2 --> CacheCheck2
TextField2 --> CacheCheck2
Video2 --> CacheCheck2
CacheCheck2{"cache<br/>exists?"}
CacheCheck2 -->|NO| EffectRender["Effect Rendering"]
CacheCheck2 -->|YES| BranchArrays
EffectRender --> BranchArrays
BranchArrays["Instanced Arrays<br/>━━━━━━━━━━━━━━━<br/>matrix<br/>colorTransform<br/>Coordinates<br/>━━━━━━━━━━━━━━━<br/><b>Batch Rendering</b>"]
BranchArrays -->|drawArraysInstanced<br/><b>Multiple objects in one call</b>| BranchRender["Effect Result"]
BranchRender -->|filter/blend| TextureCache
end
%% Connections between flows
FilterBlendCheck -.->|"trigger<br/>branch flow"| BranchFlow
BranchArrays -.->|"rendering info<br/>(coordinates)"| MainArrays
Next2D Player uses a DisplayList architecture similar to Flash Player.
DisplayObject (Base class)
├── InteractiveObject
│ ├── DisplayObjectContainer
│ │ ├── Sprite
│ │ ├── MovieClip
│ │ └── Stage
│ └── TextField
├── Shape
├── Video
└── Bitmap
Container class that can hold child objects:
addChild(child): Add child to the frontaddChildAt(child, index): Add child at specified indexremoveChild(child): Remove childgetChildAt(index): Get child by indexgetChildByName(name): Get child by nameDisplayObject with timeline animation:
play(): Start timeline playbackstop(): Stop timelinegotoAndPlay(frame): Go to frame and playgotoAndStop(frame): Go to frame and stopcurrentFrame: Current frame numbertotalFrames: Total number of framesconst { MovieClip } = next2d.display;
const { DropShadowFilter } = next2d.filters;
// Initialize stage
const root = await next2d.createRootMovieClip(800, 600, 60, {
tagId: "container",
bgColor: "#ffffff"
});
// Create MovieClip
const mc = new MovieClip();
root.addChild(mc);
// Set position and size
mc.x = 100;
mc.y = 100;
mc.scaleX = 2;
mc.scaleY = 2;
mc.rotation = 45;
// Apply filters
mc.filters = [
new DropShadowFilter(4, 45, 0x000000, 0.5)
];
Load and render JSON files created with Open Animation Tool:
const { Loader } = next2d.display;
const { URLRequest } = next2d.net;
const loader = new Loader();
await loader.load(new URLRequest("animation.json"));
const mc = loader.content;
stage.addChild(mc);