Makes a material: a shader of your own, and for models the surface it is drawn over.
Exampleconst Level = () => {
const texture = useLoadTexture({ src: '/assets/hero.png' });
const crt = createMaterial({
fragment: `fn effect(color: vec4<f32>, uv: vec2<f32>) -> vec4<f32> {
let band = 0.5 + 0.5 * sin(uv.y * mu.lines + mu.time * 6.0);
return vec4<f32>(color.rgb * band, color.a);
}`,
uniforms: { lines: 200 },
});
createSprite({ texture, material: crt });
return createScene();
};
Full entry in the referencePuts a model in the scene: a shape, somewhere, with a surface.
createMesh(options: TMeshOptions) => TMesh
Exampleconst Level = () => {
useCamera3d({ projection: 'perspective', transform: { z: 4 } });
const crate = createMesh({ geometry: useCubeGeometry(), tint: '#c08040' });
useUpdate((delta) => {
crate.transform.rotationY += delta;
});
return createScene();
};
Full entry in the referencePuts many of one shape in the scene, drawn in one go: a field of grass, a hillside of rocks, a forest.
createMeshInstances(options: TMeshInstancesOptions) => TMeshInstances
Exampleconst rocks = createMeshInstances({ geometry: useCubeGeometry(), tint: '#8a8f98', capacity: 500 });
for (let i = 0; i < 500; i++) {
rocks.set(i, {
x: Math.random() * 40 - 20,
z: Math.random() * 40 - 20,
rotationY: Math.random() * Math.PI,
scale: 0.5 + Math.random(),
});
}
Full entry in the referencePuts a loaded model in the scene.
createModel(options: TModelOptions) => TModel
Exampleconst Level = () => {
useCamera3d({ projection: 'perspective', transform: { z: 6 } });
useDirectionalLight({ intensity: 1 });
const tower = useLoadModel({ src: '/models/tower.glb' });
const placed = createModel({ model: tower, transform: { y: -1 } });
useUpdate((delta) => {
placed.transform.rotationY += delta * 0.5;
});
return createScene();
};
Full entry in the referencePuts a picture in the scene that can be any size without deforming: a panel, a button, a dialogue box, a health bar.
createNineSlice(options: TNineSliceOptions) => TNineSlice
Exampleexport const Menu: TSceneFn = () => {
useLoadTexture({ src: '/assets/ui/panel.png', key: 'panel' });
const panel = createNineSlice({
key: 'panel',
slice: 8,
width: 200,
height: 64,
transform: { x: 160, y: 120 },
onClick: () => { panel.width += 16; },
});
return createScene();
};
Full entry in the referencePlaces one thing a pack offers: a box, or a scene as one part of the scene that creates it.
createPack(options: TPackOptions) => TGameObject
Exampleconst Menu: TSceneFn = () => {
const ui = useLoadPack({ src: '/packs/ui-kit' });
createPack({ pack: ui, box: 'Button', transform: { x: 160, y: 120 } });
createPack({ pack: ui, box: 'Button', transform: { x: 160, y: 160 }, props: { label: 'QUIT' } });
return createScene();
};
Full entry in the referencePuts an emitter in the scene: a place that makes particles, following an effect from a file.
createParticles(options: TParticlesOptions) => TParticles
Exampleconst Level = () => {
const fire = useLoadParticles({ src: '/effects/fire.particles' });
createParticles({ effect: fire, transform: { x: 150, y: 250 } });
return createScene();
};
Full entry in the referencePuts an emitter in a scene in three dimensions, following an effect written for them.
createParticles3d(options: TParticles3dOptions) => TParticles3d
Exampleconst Campfire = () => {
const fire = useLoadParticles({ src: '/effects/campfire3d.particles' });
createParticles3d({ effect: fire, transform: { y: 0.1 } });
return createScene();
};
Full entry in the referencePuts a shape in the scene whose corners the game moves: a picture stretched over an outline that can change every frame.
createPolygon(options: TPolygonOptions) => TPolygon
Exampleexport const Pond: TSceneFn = () => {
// A blob of twelve corners round a circle, wobbling.
const corners = Array.from({ length: 12 }, (_, i) => ({ angle: (i / 12) * Math.PI * 2 }));
const blob = createPolygon({
points: corners.map(({ angle }) => ({ x: Math.cos(angle) * 24, y: Math.sin(angle) * 24 })),
tint: '#5bd75b',
transform: { x: 160, y: 90 },
});
useUpdate((_delta, time) => {
corners.forEach(({ angle }, i) => {
const r = 24 + Math.sin(time * 4 + angle * 3) * 3;
blob.points[i].x = Math.cos(angle) * r;
blob.points[i].y = Math.sin(angle) * r;
});
});
return createScene();
};
Full entry in the referencePuts shapes in the scene, drawn by the graphics card as they are each frame: rectangles, with rounded corners or not, circles, ellipses and slices of them, outlines of any number of corners (hollowed in too, a star or a letter), and lines as wide as asked for.
createShapes(options: TShapesOptions) => TShapes
Exampleexport const Level: TSceneFn = () => {
let life = 1;
let cooldown = 0;
const hud = createShapes({
transform: { x: 8, y: 8 },
shapes: [
{ type: 'rect', x: 0, y: 0, width: 60, height: 6, radius: 2, fill: '#e15554' },
{ type: 'rect', x: 0, y: 0, width: 60, height: 6, radius: 2, stroke: { width: 1, color: '#ffffff', align: 'outside' } },
{ type: 'circle', x: 80, y: 3, radius: 6, start: -Math.PI / 2, end: -Math.PI / 2, fill: '#ffd23f' },
],
});
const bar = hud.shapes[0] as TShapeRect;
const pie = hud.shapes[2] as TShapeCircle;
useUpdate((delta) => {
cooldown = Math.min(1, cooldown + delta / 3);
bar.width = 60 * life;
pie.end = -Math.PI / 2 + cooldown * Math.PI * 2;
});
return createScene();
};
Full entry in the referenceMakes a picture and fills it with a component: whatever component draws, and whatever it creates with useSpawn, ends up in the picture instead of on the screen, every frame.
createSpriteTexture(options: TSpriteTextureOptions, component?: (args: TArgs) => unknown, args: TArgs) => TTexture
Exampleconst Screen = () => {
const pet = createSprite({ key: 'pet', transform: { x: 40, y: 40 } });
useUpdate((delta) => {
pet.transform.x += delta * 10;
});
};
const Level = () => {
useCamera3d({ projection: 'perspective', transform: { z: 3 } });
const screen = createSpriteTexture({ width: 128, height: 128 }, Screen);
createMesh({ geometry: useCubeGeometry(), texture: screen });
return createScene();
};
Full entry in the referenceWrites something on screen with a bitmap font: a score, a title, a menu, "PRESS START".
createText(options: TTextOptions) => TText
Exampleexport const Level: TSceneFn = () => {
// No font given: the engine's own.
const score = createText({ text: 'SCORE 0', style: { fontSize: 16 }, transform: { x: 8, y: 8 } });
// A font of your own, loaded from its two files.
const font = useLoadBitmapFont({ json: '/fonts/arcade/arcade.json', atlas: '/fonts/arcade/arcade.png' });
createText({ text: 'HI SCORE', font, transform: { x: 8, y: 28 } });
// A font an earlier scene loaded with useLoadFont({ src, key: 'title' }), by its key alone.
createText({ text: 'LEVEL 1', font: 'title', transform: { x: 8, y: 48 } });
let points = 0;
useUpdate(() => {
points += 1;
score.text = 'SCORE ' + points;
});
return createScene();
};
Full entry in the referenceA view of the world in a rectangle of the screen: half of a split screen, a minimap in a corner, a rear-view mirror.
createView(options: TViewOptions, component?: (args: TArgs) => unknown, args: TArgs) => TSprite
Exampleconst Half = (player: TSprite) => {
useCamera2d();
useCameraFollow(player);
};
const Level = () => {
useWorldOffScreen();
const p1 = createSprite({ key: 'hero', transform: { x: 40, y: 200 } });
const p2 = createSprite({ key: 'hero', transform: { x: 120, y: 200 } });
createView({ x: 0, y: 0, width: 240, height: 270 }, Half, p1);
createView({ x: 240, y: 0, width: 240, height: 270 }, Half, p2);
return createScene();
};
Full entry in the reference