Documentation
Kiwi Engine is a TypeScript-based 2D web game engine. It features a center-origin coordinate system (canvas center is 0,0), responsive canvas, layers/camera, and both Canvas and DOM render nodes.
Quick Start
- Install
kiwiengine
in your project.npm install kiwiengine
- Create a
Renderer
and configure layers. - Create a
GameObject
and add it torenderer
.
import { Renderer, GameObject } from 'kiwiengine'
const renderer = new Renderer(document.body, {
layers: [
{ name: 'background', drawOrder: 0 },
{ name: 'game', drawOrder: 1 },
{ name: 'ui', drawOrder: 2 },
]
})
const player = new GameObject({ x: 0, y: 0, layer: 'game' })
renderer.add(player)
Core Concepts
- Center-Origin Coordinates — The canvas center is (0,0). Use
screenToWorld(x,y)
for screen→world conversion. - Responsive Canvas — Automatically resizes to match the parent element.
- Layers/Camera — Control draw order and pan/zoom the camera.
- Time-based Updates —
Ticker
providesdt
in seconds; debug mode caps unfocused tabs at 6 FPS.
Main Nodes
- GameObject — Transform (position/rotation/scale/layer), children management.
- SpriteNode / AnimatedSpriteNode — Texture/spritesheet rendering.
- BitmapTextNode — Bitmap-font text rendering.
- CircleNode / RectangleNode — Primitive shapes.
- SpineNode — Spine animation.
- ParticleSystem — Simple burst particles.
- Dom* — DOM-based nodes (sprite/animated/particle/container).
Collision/Physics
- checkCollision — Supports rect/circle/ellipse/polygon.
- PhysicsWorld / PhysicsObject — Gravity/collision simulation with render transform sync.
Audio
- musicPlayer — BGM player (volume persisted in
localStorage
). - sfxPlayer — Lightweight sound effects.
Debug
Toggle debug mode with enableDebug()
. Unfocused tabs run at a fixed 6 FPS step in debug.