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', z: 4 });
const crate = createMesh({ geometry: useCubeGeometry(), tint: getColor('#c08040') });
useUpdate((delta) => {
crate.transform.rotationY += delta;
});
return createScene();
};
Full entry in the referencePuts a loaded model in the scene.
createModel(options: TModelOptions) => TModel
Exampleconst Level = () => {
useCamera3d({ projection: 'perspective', z: 6 });
useLight({ intensity: 1 });
const tower = useLoadGltf({ 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) => TBox
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 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', 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 = useLoadFont({ json: '/fonts/arcade/arcade.json', atlas: '/fonts/arcade/arcade.png' });
createText({ text: 'HI SCORE', font, transform: { x: 8, y: 28 } });
let points = 0;
useUpdate(() => {
points += 1;
score.text = 'SCORE ' + points;
});
return createScene();
};
Full entry in the reference