Game FrameWork for JavaScript 2D WebGL Canvas Games
npm install make2dmake2d is a lightweight game framework for building 2D WebGL games in JavaScript.
It provides a Unity-inspired architecture on top of PIXI.js, focusing on:
- predictable object hierarchy
- safe lifecycle management
- efficient collision detection
- reactive, composable update loops
- fast, mobile-friendly rendering (PIXI.js)
- Unity-like scene & entity hierarchy
- lifecycle-safe object destruction
- efficient 2D collision system (check2d)
- RxJS-driven update & event model
---
š https://nenjack.github.io/make2d/demo/?fps&debug
---
``ts
import { Scene, GameObject } from 'make2d'
import { takeUntil } from 'rxjs'
const scene = new Scene({
visible: true,
autoSort: true
})
// scene-level update loop
scene.update$.pipe(takeUntil(scene.destroy$)).subscribe(() => {
scene.physics.separate()
})
const gameObject = new GameObject('Entity Name')
scene.addChild(gameObject)
// game object update loop
gameObject.update$
.pipe(takeUntil(gameObject.destroy$))
.subscribe((deltaTime) => {
gameObject.update(gameObject, deltaTime)
})
`
---
``
[HTML5 Canvas + WebGL]
āāā [Scene]
āāā [Collision System]
āāā [GameObject x 50]
āāā [Body]
āāā [Animator]
āāā [StateMachine]
The hierarchy and API are intentionally similar to Unity, making it easy to reason about complex scenes.
---
When building multiple indie and HTML5 WebGL games, a few recurring problems show up:
1. managing deeply nested game entities
2. avoiding memory leaks during object destruction
3. keeping update logic predictable and composable
make2d addresses these by design, using a strict hierarchy and lifecycle model inspired by Unity.
---
Every object in make2d participates in a tree-based lifecycle.
Examples:
- tank ā turret ā ammohouse ā furniture ā props
-
- All framework classes implement Lifecycle
- Destroying any object:
- emits and completes destroy$
- recursively destroys all children
- RxJS subscriptions can safely bind to destroy$
- Every object exposes an update$ observabledeltaTime
- Updates flow top-down through the hierarchy
- When a parent updates, all children update automatically
- is provided each frame
This makes it easy to compose behavior without manual bookkeeping.
---
make2d provides a small but complete set of building blocks:
- Lifecycle ā destroy entire branches safely
- Component ā base class for attachable behavior
- GameObject ā Unity-like entity container
- Scene ā root container and game entry point
- SceneSSR ā Scene replacement for Node.js
- Container ā PIXI.Container + lifecyclePIXI.Sprite
- Sprite ā + lifecyclePIXI.AnimatedSprite
- Animator ā manages multiple
- TextureAtlas ā atlas frame slicing
- StateMachine ā simple state handling
- Prefab ā declarative entity creation
- Resources ā asset loader
- CircleBody ā circular collider
- BoxBody ā rectangular collider
- PolygonBody ā polygon collider
---
`bash``
yarn add make2d
---
- API reference
https://nenjack.github.io/make2d/modules.html
- Lifecycle & hierarchy
https://nenjack.github.io/make2d/hierarchy.html
---
MIT