English | Chinese
Eva.js is a front-end game engine specifically for creating interactive game projects.
Easy to Use: Eva.js provides out-of-box game components for developers to use right away. Yes, it's simple and elegant!
High-performance: Eva.js is powered by efficient runtime and rendering pipeline (Pixi.JS) which makes it possible to unleash the full potential of your device.
Scalability: Thanks to the ECS(Entity-Component-System) structure, you can expand your needs by highly customizable APIs. The only limitation is your imagination!
You can find the Eva.js Documentation on eva.js.org, we appreciate your devotion by sending pull requests to this repository.
Checking out the Live example.
| Package | Description |
|---|---|
@eva/eva.js |
Core engine: Game, GameObject, Component, System, Resource |
@eva/plugin-renderer |
Core renderer (PixiJS) |
@eva/plugin-renderer-img |
Image rendering |
@eva/plugin-renderer-text |
Text rendering (Text, HTMLText, BitmapText) |
@eva/plugin-renderer-sprite |
Sprite sheet rendering |
@eva/plugin-renderer-sprite-animation |
Frame animation |
@eva/plugin-renderer-spine |
Spine skeleton animation |
@eva/plugin-renderer-dragonbone |
DragonBones skeleton animation |
@eva/plugin-renderer-lottie |
Lottie animation |
@eva/plugin-renderer-graphics |
Vector graphics drawing |
@eva/plugin-renderer-nine-patch |
Nine-slice scaling |
@eva/plugin-renderer-tiling-sprite |
Tiling sprite |
@eva/plugin-renderer-mask |
Mask / clipping |
@eva/plugin-renderer-mesh |
Perspective mesh deformation |
@eva/plugin-renderer-render |
Render properties (alpha, zIndex, visible) |
@eva/plugin-renderer-event |
Touch / pointer events |
@eva/plugin-sound |
Audio playback |
@eva/plugin-transition |
Tween animation |
@eva/plugin-a11y |
Accessibility |
@eva/plugin-evax |
Global state management |
@eva/plugin-matterjs |
Physics engine (Matter.js) |
@eva/plugin-layout |
Flexbox layout |
@eva/plugin-stats |
Performance monitor |
npm i @eva/eva.js @eva/plugin-renderer @eva/plugin-renderer-img --save
<canvas id="canvas"></canvas>
import { Game, GameObject, resource, RESOURCE_TYPE } from '@eva/eva.js';
import { RendererSystem } from '@eva/plugin-renderer';
import { Img, ImgSystem } from '@eva/plugin-renderer-img';
resource.addResource([
{
name: 'imageName',
type: RESOURCE_TYPE.IMAGE,
src: {
image: {
type: 'png',
url: 'https://gw.alicdn.com/tfs/TB1DNzoOvb2gK0jSZK9XXaEgFXa-658-1152.webp',
},
},
preload: true,
},
]);
const game = new Game();
await game.init({
systems: [
new RendererSystem({
canvas: document.querySelector('#canvas'),
width: 750,
height: 1000,
}),
new ImgSystem(),
],
});
const image = new GameObject('image', {
size: { width: 750, height: 1319 },
origin: { x: 0, y: 0 },
position: { x: 0, y: -319 },
anchor: { x: 0, y: 0 },
});
image.addComponent(
new Img({
resource: 'imageName',
}),
);
game.scene.addChild(image);
@eva/eva.jsGame engine entry. Manages systems, scenes, and the game loop.
import { Game } from '@eva/eva.js';
const game = new Game();
await game.init({
autoStart: true, // auto start the game loop (default: true)
frameRate: 60, // target frame rate (default: 60)
systems: [], // systems to register
needScene: true, // auto create default scene (default: true)
});
| Method | Description |
|---|---|
addSystem(system) |
Register a system |
removeSystem(system) |
Remove a system |
getSystem(SystemClass) |
Get registered system instance |
start() |
Start the game loop |
pause() |
Pause the game loop |
resume() |
Resume the game loop |
destroy() |
Destroy the game |
loadScene({ scene, mode?, params? }) |
Load a scene |
findByName(name) |
Find first GameObject by name |
findAllByName(name) |
Find all GameObjects by name |
| Property | Description |
|---|---|
scene |
Current main scene |
playing |
Whether the game is running |
ticker |
Ticker instance |
systems |
Registered systems array |
Entity in the ECS architecture. Holds components and supports parent-child hierarchy.
import { GameObject } from '@eva/eva.js';
const go = new GameObject('name', {
position: { x: 0, y: 0 },
size: { width: 100, height: 100 },
origin: { x: 0, y: 0 }, // transform origin
anchor: { x: 0.5, y: 0.5 }, // anchor point
scale: { x: 1, y: 1 },
rotation: 0, // radians
skew: { x: 0, y: 0 },
});
| Method | Description |
|---|---|
addComponent(component) |
Add a component instance |
addComponent(ComponentClass, params) |
Add component by class + params |
removeComponent(component) |
Remove a component |
getComponent(ComponentClass) |
Get component by class |
addChild(gameObject) |
Add child GameObject |
removeChild(gameObject) |
Remove child GameObject |
remove() |
Remove self from parent |
destroy() |
Destroy self and all children |
| Property | Description |
|---|---|
transform |
Transform component |
parent |
Parent GameObject |
children |
Child GameObjects |
scene |
Scene this object belongs to |
Base class for all components.
import { Component } from '@eva/eva.js';
class MyComponent extends Component {
static componentName = 'MyComponent';
init(params) {} // called when added to GameObject
awake() {} // called after init
start() {} // called before first update
update({ deltaTime, time, fps }) {}
lateUpdate({ deltaTime }) {}
onPause() {}
onResume() {}
onDestroy() {}
}
Base class for all systems. Processes components each frame.
import { System } from '@eva/eva.js';
class MySystem extends System {
static systemName = 'MySystem';
init(params) {}
awake() {}
start() {}
update({ deltaTime, time, fps }) {}
lateUpdate({ deltaTime }) {}
onPause() {}
onResume() {}
onDestroy() {}
}
Global resource manager singleton.
import { resource, RESOURCE_TYPE, LOAD_EVENT } from '@eva/eva.js';
// Add resources
resource.addResource([
{
name: 'img',
type: RESOURCE_TYPE.IMAGE,
src: { image: { type: 'png', url: 'path/to/image.png' } },
preload: true,
},
]);
// Preload all preload:true resources
resource.preload();
// Listen to loading progress
resource.on(LOAD_EVENT.PROGRESS, (progress) => {}); // 0-1
resource.on(LOAD_EVENT.COMPLETE, () => {});
resource.on(LOAD_EVENT.ERROR, (err) => {});
// Get resource (async)
const res = await resource.getResource('img');
// Destroy resource
resource.destroy('img');
RESOURCE_TYPE: IMAGE, SPRITE, SPRITE_ANIMATION, AUDIO, VIDEO, FONT
@eva/plugin-rendererCore rendering system powered by PixiJS. Required by all renderer plugins.
import { RendererSystem } from '@eva/plugin-renderer';
new RendererSystem({
canvas: document.querySelector('#canvas'),
width: 750,
height: 1000,
preference: 'webgl', // 'webgl' | 'webgpu' | 'canvas'
backgroundAlpha: 1, // 0=fully transparent, 1=opaque
antialias: false,
resolution: window.devicePixelRatio,
backgroundColor: 0x000000,
enableScroll: false,
debugMode: false,
});
| Method | Description |
|---|---|
resize(width, height) |
Resize the canvas |
@eva/plugin-renderer-imgRender a single image.
import { Img, ImgSystem } from '@eva/plugin-renderer-img';
// Register system
game.addSystem(new ImgSystem());
// Add component
go.addComponent(new Img({ resource: 'imageName' }));
| Param | Type | Description |
|---|---|---|
resource |
string |
Resource name (IMAGE type) |
@eva/plugin-renderer-spriteRender a sub-image from a sprite sheet.
import { Sprite, SpriteSystem } from '@eva/plugin-renderer-sprite';
game.addSystem(new SpriteSystem());
go.addComponent(new Sprite({
resource: 'spriteName',
spriteName: 'frame01.png',
}));
| Param | Type | Description |
|---|---|---|
resource |
string |
Resource name (SPRITE type) |
spriteName |
string |
Sub-image name in the sprite sheet |
@eva/plugin-renderer-sprite-animationPlay frame-by-frame animation from a sprite sheet.
import { SpriteAnimation, SpriteAnimationSystem } from '@eva/plugin-renderer-sprite-animation';
game.addSystem(new SpriteAnimationSystem());
const anim = go.addComponent(new SpriteAnimation({
resource: 'animResource',
autoPlay: true,
speed: 100, // ms per frame
forwards: false, // stop at last frame when done
}));
anim.play(3); // play 3 times
anim.gotoAndPlay(5); // jump to frame 5 and play
anim.gotoAndStop(0); // jump to frame 0 and stop
anim.stop();
| Param | Type | Default | Description |
|---|---|---|---|
resource |
string |
Resource name (SPRITE_ANIMATION type) | |
autoPlay |
boolean |
true |
Auto play on load |
speed |
number |
100 |
Milliseconds per frame |
forwards |
boolean |
false |
Freeze on last frame when complete |
| Property | Description |
|---|---|
currentFrame |
Current frame number |
totalFrames |
Total frame count |
| Event | Description |
|---|---|
complete |
All play iterations finished |
loop |
Each loop iteration |
frameChange |
Frame changed |
@eva/plugin-renderer-textRender text content with three rendering modes.
import { Text, HTMLText, BitmapText, TextSystem } from '@eva/plugin-renderer-text';
game.addSystem(new TextSystem());
// Canvas Text
go.addComponent(new Text({
text: 'Hello World',
style: {
fontFamily: 'Arial',
fontSize: 36,
fill: 0xff1010,
stroke: { color: 0xffffff, width: 5 },
fontWeight: 'bold',
wordWrap: true,
wordWrapWidth: 200,
align: 'center',
dropShadow: {
alpha: 1, angle: Math.PI / 6,
blur: 5, color: 0x000000, distance: 5,
},
},
}));
// HTML Rich Text (supports <b>, <i>, <span>,
tags)
go.addComponent(new HTMLText({
text: '<b>Bold</b> and <i>italic</i>',
style: {
fontFamily: 'Arial',
fontSize: 24,
fill: 0x000000,
wordWrap: true,
wordWrapWidth: 300,
},
}));
// Bitmap Text (using bitmap font resource)
go.addComponent(new BitmapText({
text: 'Score: 100',
style: {
fontFamily: 'myBitmapFont',
fontSize: 32,
},
}));
@eva/plugin-renderer-graphicsDraw vector shapes using PixiJS Graphics API.
import { Graphics, GraphicsSystem } from '@eva/plugin-renderer-graphics';
game.addSystem(new GraphicsSystem());
const comp = go.addComponent(new Graphics());
// Use PixiJS Graphics API directly
comp.graphics.rect(0, 0, 100, 100);
comp.graphics.fill(0xff0000);
comp.graphics.circle(50, 50, 30);
comp.graphics.fill(0x00ff00);
@eva/plugin-renderer-nine-patchNine-slice scaling. Corners stay fixed while edges and center stretch.
import { NinePatch, NinePatchSystem } from '@eva/plugin-renderer-nine-patch';
game.addSystem(new NinePatchSystem());
go.addComponent(new NinePatch({
resource: 'panelImg',
leftWidth: 20,
topHeight: 20,
rightWidth: 20,
bottomHeight: 20,
}));
| Param | Type | Description |
|---|---|---|
resource |
string |
Image or sprite resource name |
spriteName |
string |
Sub-image name (when using SPRITE resource) |
leftWidth |
number |
Left non-stretch width |
topHeight |
number |
Top non-stretch height |
rightWidth |
number |
Right non-stretch width |
bottomHeight |
number |
Bottom non-stretch height |
$ claude mcp add eva.js \
-- python -m otcore.mcp_server <graph>