Documentation
A quick-start guide and overview of Bloom's public modules.
Language: The technical reference is maintained in English. The language menu opens localized marketing pages.
Version: The quick-start is type-checked against npm 0.4.16. The complete 13-module inventory and Texture.handle reflect the active 0.5 development branch; stable 0.4 uses Texture.id and does not yet export VFX or Quality. See the 0.5 migration guide.
Quick Start
Install the engine with npm install @bloomengine/engine. This complete example opens a window, clears it each frame, draws text, and exits when the user closes the window.
import { initWindow, windowShouldClose, beginDrawing,
endDrawing, clearBackground, drawText,
Colors, closeWindow } from "@bloomengine/engine";
initWindow(800, 450, "Hello Bloom");
while (!windowShouldClose()) {
beginDrawing();
clearBackground(Colors.SNOW);
drawText("Hello, Bloom!", 190, 200, 20, Colors.DARKGRAY);
endDrawing();
}
closeWindow(); Core Concepts
The Game Loop
Every Bloom game follows the same pattern: initialize, loop, clean up. There's no hidden framework — you own the loop.
initWindow(800, 600, "My Game");
setTargetFPS(60);
while (!windowShouldClose()) {
const dt = getDeltaTime(); // seconds since last frame
// 1. Update game state
playerX = playerX + speed * dt;
// 2. Draw everything
beginDrawing();
clearBackground(Colors.BLACK);
// ... draw calls here ...
endDrawing();
}
closeWindow(); Delta Time
getDeltaTime() returns the time in seconds since the last frame. Always multiply movement and animation values by delta time to keep behavior consistent regardless of frame rate.
Drawing Lifecycle
All draw calls must happen between beginDrawing() and endDrawing(). Bloom batches and submits GPU commands when you call endDrawing().
Function-first, minimal abstraction
Bloom's gameplay API uses functions, handles, and plain data types such as Vec2, Color, and Rect. Math helpers return new values rather than mutating their inputs. Specialized tooling modules may expose a helper class, such as QualityRun.
Project Structure
my-game/
src/
main.ts # Entry point
player.ts
enemies.ts
assets/
sprites/ # PNG, JPG
models/ # glTF, OBJ
sounds/ # WAV, OGG, MP3
fonts/ # TTF, OTF
package.json Bloom modules are independently importable. Use only what you need:
import { initWindow } from "@bloomengine/engine/core";
import { drawRect } from "@bloomengine/engine/shapes";
import { vec3Add } from "@bloomengine/engine/math";
// Or import everything from the barrel export:
import { initWindow, drawRect, vec3Add } from "@bloomengine/engine"; API Reference
Core
@bloomengine/engine/core Window management, game loop, input handling, timing, and utility functions.
Window
Drawing
endDrawing().Timing
Keyboard Input
Mouse Input
Touch Input
Gamepad Input
Camera Modes
File I/O
Shapes
@bloomengine/engine/shapes 2D shape drawing and collision detection.
Drawing
2D Collision Detection
Textures
@bloomengine/engine/textures Image loading, texture management, and sprite rendering. Supports PNG, JPG, BMP, and TGA.
Textures
Colors.WHITE for no tint.Images (CPU-side)
Text
@bloomengine/engine/text Font loading and text rendering. Supports TTF and OTF fonts.
Audio
@bloomengine/engine/audio Sound effects and music streaming. Supports WAV, OGG, and MP3.
System
Sound Effects
Music Streaming
Models
@bloomengine/engine/models 3D model loading, primitive drawing, mesh generation, and shaders. Supports glTF and OBJ.
3D Models
3D Primitives
Mesh Generation
Shaders & Animation
Math
@bloomengine/engine/math Vectors, matrices, quaternions, easing functions, collision, and utilities. All functions are pure — they return new values and never mutate inputs.
Vector 2D
Vector 3D
Vector 4D
Matrix 4x4
Mat4 is a number[] with 16 elements in column-major order.
Quaternions
3D Collision & Raycasting
Frustum Culling
Scalar Utilities
Easing Functions
All easing functions take a t value from 0.0 to 1.0 and return a transformed value.
Additional public modules
The package exports all thirteen modules below. These module summaries link to the canonical source or focused guides for the full current surface.
Mobile
@bloomengine/engine/mobileVirtual joysticks, virtual buttons, safe-area handling, and touch-oriented input helpers.
Scene
@bloomengine/engine/sceneRetained scene nodes, transforms, geometry, material bindings, visibility, lights, picking, and frame callbacks.
Physics
@bloomengine/engine/physicsJolt-backed worlds, shapes, bodies, constraints, characters, vehicles, queries, and contact events.
World
@bloomengine/engine/worldVersioned .world.json loading, migration, validation, prefab expansion, instantiation, and environment application.
VFX
@bloomengine/engine/vfxGPU particle emitters, particle-system updates and drawing, plus decal creation and lifecycle helpers.
Quality
@bloomengine/engine/qualityDeterministic qualification windows, captures, telemetry, and the QualityRun helper used by renderer examples.
Reference
Types
The core data types shown here are plain interfaces and object literals. Specialized helper modules may additionally expose classes.
// Vectors
interface Vec2 { x: number; y: number }
interface Vec3 { x: number; y: number; z: number }
interface Vec4 { x: number; y: number; z: number; w: number }
// Visual
interface Color { r: number; g: number; b: number; a: number } // 0-255
interface Rect { x: number; y: number; width: number; height: number }
// Cameras
interface Camera2D {
offset: Vec2; // camera offset (screen center)
target: Vec2; // camera target (world position)
rotation: number; // rotation in degrees
zoom: number; // zoom level (1.0 = no zoom)
}
interface Camera3D {
position: Vec3; // camera position
target: Vec3; // look-at point
up: Vec3; // up direction
fovy: number; // field of view Y (degrees)
projection: "perspective" | "orthographic";
}
// Resources (handle-based)
interface Texture { handle: number; width: number; height: number }
interface Font { handle: number; size: number }
interface Sound { handle: number }
interface Music { handle: number }
interface Model { handle: number }
// Quaternion
interface Quat { x: number; y: number; z: number; w: number }
// 3D Geometry
interface Ray { position: Vec3; direction: Vec3 }
interface BoundingBox { min: Vec3; max: Vec3 }
interface RayHit {
hit: boolean; distance: number;
point: Vec3; normal: Vec3;
}
interface FrustumPlanes { planes: Vec4[] }
// Matrix (column-major, 16 elements)
type Mat4 = number[]; Colors
Pre-defined colors available via Colors.NAME. Import from @bloomengine/engine/core.
Custom colors are plain objects: { r: 255, g: 100, b: 50, a: 255 }
Key Constants
Import Key and MouseButton from @bloomengine/engine/core.
Keyboard
Letters
Key.A – Key.Z Numbers
Key.ZERO – Key.NINE Function Keys
Key.F1 – Key.F12 Arrows
Key.UP, Key.DOWN, Key.LEFT, Key.RIGHT Common
Key.SPACE, Key.ENTER, Key.ESCAPE, Key.TAB, Key.BACKSPACE, Key.DELETE Navigation
Key.INSERT, Key.HOME, Key.END, Key.PAGE_UP, Key.PAGE_DOWN Modifiers
Key.LEFT_SHIFT, Key.RIGHT_SHIFT, Key.LEFT_CONTROL, Key.RIGHT_CONTROL, Key.LEFT_ALT, Key.RIGHT_ALT, Key.LEFT_SUPER, Key.RIGHT_SUPER Punctuation
Key.COMMA, Key.PERIOD, Key.SLASH, Key.SEMICOLON, Key.APOSTROPHE, Key.MINUS, Key.EQUAL, Key.LEFT_BRACKET, Key.RIGHT_BRACKET, Key.BACKSLASH, Key.GRAVE Mouse Buttons
MouseButton.LEFT, MouseButton.RIGHT, MouseButton.MIDDLE Guides
Input Handling
Bloom distinguishes between pressed (single frame), down (held), and released (single frame) states.
// One-shot actions (menus, jumping, shooting)
if (isKeyPressed(Key.SPACE)) jump();
if (isKeyPressed(Key.ENTER)) selectMenuItem();
// Continuous movement (hold to move)
if (isKeyDown(Key.LEFT)) x -= speed * dt;
if (isKeyDown(Key.RIGHT)) x += speed * dt;
if (isKeyDown(Key.W)) y -= speed * dt;
if (isKeyDown(Key.S)) y += speed * dt;
// Mouse
const mouse = getMousePosition();
if (isMouseButtonPressed(MouseButton.LEFT)) {
shoot(mouse.x, mouse.y);
} Cameras
2D Camera
The 2D camera transforms all draw calls between beginMode2D and endMode2D. Set offset to the screen center and target to the world position you want to follow.
const camera: Camera2D = {
offset: { x: 400, y: 300 }, // center of 800x600 screen
target: { x: player.x, y: player.y }, // follow player
rotation: 0,
zoom: 1.0
};
// Smooth follow
camera.target.x += (player.x - camera.target.x) * 8 * dt;
camera.target.y += (player.y - camera.target.y) * 8 * dt;
beginMode2D(camera);
// World-space drawing here — moves with camera
drawRect(player.x, player.y, 32, 32, Colors.BLUE);
endMode2D();
// Screen-space drawing here — stays fixed (HUD)
drawText("Score: 100", 10, 10, 20, Colors.WHITE); 3D Camera
const camera: Camera3D = {
position: { x: 10, y: 10, z: 10 }, // eye position
target: { x: 0, y: 0, z: 0 }, // look-at point
up: { x: 0, y: 1, z: 0 }, // up direction
fovy: 45, // field of view (degrees)
projection: "perspective"
};
beginMode3D(camera);
drawCube({ x: 0, y: 0, z: 0 }, 2, 2, 2, Colors.RED);
drawGrid(10, 1);
endMode3D(); Collision Detection
Bloom provides both 2D and 3D collision detection. All collision functions are pure and return results without side effects.
// Rectangle vs Rectangle (AABB)
const player: Rect = { x: 100, y: 100, width: 32, height: 32 };
const enemy: Rect = { x: 120, y: 110, width: 32, height: 32 };
if (checkCollisionRecs(player, enemy)) {
// Get the overlap area
const overlap = getCollisionRec(player, enemy);
}
// Circle vs Circle
if (checkCollisionCircles(
{ x: 100, y: 100 }, 20, // center1, radius1
{ x: 130, y: 110 }, 15 // center2, radius2
)) {
// collision!
}
// Point in rectangle (mouse clicks, UI)
const mouse = getMousePosition();
if (checkCollisionPointRec(mouse, button)) {
// hovering over button
} Audio
Sound effects are fully loaded into memory — use them for short clips. Music is streamed — use it for background tracks. Always call updateMusicStream every frame.
initAudio();
// Sound effects (loaded fully, play instantly)
const hitSound = loadSound("sounds/hit.wav");
const coinSound = loadSound("sounds/coin.ogg");
setSoundVolume(coinSound, 0.7);
// Background music (streamed)
const bgm = loadMusic("music/theme.ogg");
setMusicVolume(bgm, 0.5);
playMusic(bgm);
while (!windowShouldClose()) {
updateMusicStream(bgm); // REQUIRED every frame
if (playerHit) playSound(hitSound);
if (coinCollected) playSound(coinSound);
// ... drawing ...
}
closeAudio(); Examples
Pong
Classic two-player Pong. Demonstrates the game loop, keyboard input, delta-time movement, 2D shapes, collision detection, text rendering, and score tracking.
What you'll learn
- Game loop with
getDeltaTime()for frame-rate independence - Continuous input with
isKeyDown()for paddle movement - Rectangle collision with
checkCollisionRecs() - Centered text using
measureText() - Game state management (pause, scoring, ball reset)
- Value clamping with
clamp()to keep paddles on screen
const ballRect: Rect = {
x: ballX - BALL_RADIUS, y: ballY - BALL_RADIUS,
width: BALL_RADIUS * 2, height: BALL_RADIUS * 2
};
if (checkCollisionRecs(ballRect, leftPaddle) && ballVelX < 0) {
ballVelX = -ballVelX;
// Angle varies based on where ball hits paddle
const hitPos = (ballY - leftPaddleY) / PADDLE_HEIGHT;
ballVelY = BALL_SPEED * (hitPos - 0.5) * 2;
} Dungeon Crawl
A turn-based dungeon crawler with procedural map generation, fog of war, enemy AI, and 2D camera. Descend through floors of increasing difficulty.
What you'll learn
- Procedural dungeon generation (rooms + corridors)
- Raycasting field-of-view with fog of war and exploration memory
- Turn-based logic using
isKeyPressed()(one action per press) - 2D camera with smooth follow and zoom (
beginMode2D/endMode2D) - Flat-array tile maps with
y * WIDTH + xindexing - Entity AI (enemies chase visible player, attack when adjacent)
- HUD overlay drawn outside camera mode
const camera: Camera2D = {
offset: { x: SCREEN_WIDTH / 2, y: SCREEN_HEIGHT / 2 },
target: { x: player.x * TILE_SIZE, y: player.y * TILE_SIZE },
rotation: 0, zoom: 1.0
};
// Smooth easing toward player each frame
camera.target.x += (targetX - camera.target.x) * 8 * dt;
camera.target.y += (targetY - camera.target.y) * 8 * dt;
// Zoom with +/- keys
if (isKeyDown(Key.EQUAL)) camera.zoom = clamp(camera.zoom + dt, 0.5, 3.0);
if (isKeyDown(Key.MINUS)) camera.zoom = clamp(camera.zoom - dt, 0.5, 3.0); Space Blaster
A fast-paced vertical shooter with wave-based enemy spawning, particle explosions, object pooling, and a scrolling star field.
What you'll learn
- Object pooling with fixed-size arrays and
activeflags (zero GC) - Particle system with velocity, lifetime, and alpha fade-out
- Wave-based difficulty progression (more enemies, new types per wave)
- Multiple entity types with different behavior (basic, fast, tank)
- Cooldown-based shooting (
bulletCooldown -= dt) - Parallax scrolling star background
- Triangle drawing for the player ship with
drawTriangle()
// Pre-allocate pool (no allocations during gameplay)
const particles: Particle[] = [];
for (let i = 0; i < MAX_PARTICLES; i++) {
particles.push({ x: 0, y: 0, vx: 0, vy: 0,
life: 0, maxLife: 0, color: Colors.WHITE, active: false });
}
// Spawn by reusing inactive entries
function spawnExplosion(x: number, y: number) {
for (let i = 0; i < MAX_PARTICLES; i++) {
if (!particles[i].active) {
const angle = randomFloat(0, Math.PI * 2);
const speed = randomFloat(50, 200);
particles[i].x = x; particles[i].y = y;
particles[i].vx = Math.cos(angle) * speed;
particles[i].vy = Math.sin(angle) * speed;
particles[i].life = randomFloat(0.3, 0.8);
particles[i].active = true;
break;
}
}
}