Assets & loading
Volver a la referencia

Assets & loading

Every asset hook and the loader they report through, for progress bars and preloaders.

56 símbolos

createSpriteAtlasfunctionnacatamalon

createSpriteAtlas(options: TSpriteAtlasOptions) => TSpriteAtlas

Describes a sheet as a grid of frames, so many pictures can live in one image.

This is what lets a whole game draw with one texture: sprites sharing an image are drawn together, and every change of image costs the renderer a break in the batch. A sheet is also how a character is animated, since its frames are the same picture at different moments.

Nothing is loaded here and nothing is measured: a frame is a fraction of the image, so this works the instant it is written, whether or not the image has arrived.

Parámetros

optionsTSpriteAtlasOptions

The image, and how many columns and rows of frames it holds.

Ejemplo

const walk = useLoadTexture({ src: '/assets/walk.png', key: 'walk' });
const sheet = createSpriteAtlas({ texture: walk, columns: 6 });

createSprite({ atlas: sheet, frame: 0, transform: { x: 80, y: 120 } });
Ver el código · atlas/create_sprite_atlas.ts:51

MAX_PALETTE_COLORSvariablenacatamalon

MAX_PALETTE_COLORS: 256

As many colours as a palette may hold.

Two hundred and fifty-six, which is more than any machine of the era ever showed at once, and the ceiling exists because matching walks every colour for every pixel: a palette of ten thousand would be a frame that never finishes rather than an error anybody could see.

Ver el código · loaders/palette/palette_document.ts:23

parsePaletteDocfunctionnacatamalon

parsePaletteDoc(value: unknown) => TPaletteDoc

Reads a .palette, whatever state it is in.

Total and never throws, like every other document this engine reads: a palette is edited by hand and written by tools, so one bad colour drops that colour and keeps the rest. A palette that ends up with nothing in it is still a palette, and an effect matching against an empty one gives back what it was handed, which is the honest answer to "reduce this to no colours".

Parámetros

valueunknown

Whatever JSON.parse gave back.

Ver el código · loaders/palette/palette_document.ts:53

parseParticlesDocfunctionnacatamalon

parseParticlesDoc(value: unknown, src: string) => TParticlesDoc

Reads a .particles file.

Normalizes as it reads, and names the file in every refusal. What it refuses is only what has no sensible answer: a kind of effect that is not one, a shape that is not one, a colour that is not a colour, a lifetime of zero. Everything else falls back to something an author would recognise, because an effect that loads slightly wrong can be seen and fixed, and one that does not load at all takes the scene with it.

Parámetros

valueunknown

Whatever JSON.parse gave back.

srcstring

Which file it came from, for the messages.

Ver el código · loaders/particles/parse_particles_doc.ts:306

PARTICLES_FORMATvariablenacatamalon

PARTICLES_FORMAT: 1

The format number a .particles file written today carries.

Bumped only for a change an older reader could not survive. A new optional field does not bump it, because an older reader ignoring a field it has never heard of is the whole point of having optional fields.

Ver el código · loaders/particles/types/t_particles_doc.ts:14

setSpriteFramefunctionnacatamalon

setSpriteFrame(sprite: TSprite, index: number) => void

Shows another frame of the sheet the sprite came from.

For a picture that changes without running: a chest that is open, a tile that is broken, a character facing another way. What moves through frames by itself is useSpriteAnimation, which is this called once per frame.

The one way to change frames, because what a sprite really carries is the window into its image: setting a frame number on the record would be a second truth that nothing reads.

Moves the sprite to its sheet's image too, so putting another sheet on a sprite and asking for a frame is all it takes to swap what it shows: walking to attacking, in two lines.

Does nothing to a sprite that came from no sheet, rather than throwing: asking a plain sprite to show frame 3 is a mistake worth ignoring, not worth stopping a game for.

Parámetros

spriteTSprite

A sprite made with an atlas.

indexnumber

Which frame of that sheet to show, counting from 0.

Ejemplo

declare const coins: TSpriteAtlas;

const coin = createSprite({ atlas: coins, frame: 0, transform: { x: 40, y: 40 } });
setSpriteFrame(coin, 4);
Ver el código · atlas/set_sprite_frame.ts:35

useLoadAtlasfunctionhooknacatamalon

useLoadAtlas(options: TUseLoadAtlasOptions) => TLoadedAtlas

Loads a sheet written as a file: the image, how it is cut into frames, and the named runs of frames over it.

The file-based twin of createSpriteAtlas. Slicing in code is fine while a sheet is used in one place; a file is what lets the same slicing be shared by everything that reads the sheet, and changed without touching any code, which is what an editor and an artist need.

Asking twice for the same sheet gives the same one back, already loaded, so scenes can help themselves without arranging anything between them.

What comes back can be used right away: sprites made from it show their frame when it arrives, and useLoader counts it like an image.

Parámetros

optionsTUseLoadAtlasOptions

Where the .atlas file is, and the name to keep it under.

Ejemplo

export const Level: TSceneFn = () => {
    const coin = useLoadAtlas({ src: '/assets/atlases/coin.atlas' });

    const sprite = createSprite({ atlas: coin, transform: { x: 160, y: 120 } });
    // The runs come from the file, so the clip is not written twice.
    useSpriteAnimation(sprite, { clips: coin.sequences, play: 'spin' });

    return createScene();
};
Ver el código · hooks/loaders/use_load_atlas.ts:58

useLoadAudiofunctionhooknacatamalon

useLoadAudio(options: TUseLoadAudioOptions) => TAudioClip

Loads a sound, and hands it back at once, still loading, for useSound to play.

It comes back straight away, empty, and fills itself in when the file arrives. Playing it before then does nothing, so nothing has to check whether it is ready. Asking twice for the same key gives the same sound, already loaded: load it once in a loading scene and use it in the level.

It can be watched with useLoader to show a loading bar.

This is also what opens the game's sound, so a game that never loads or plays anything never does.

Parámetros

optionsTUseLoadAudioOptions

Where the file is, and the name to keep it under.

Ejemplo

declare const chest: TSprite;

export const Level: TSceneFn = () => {
    const coin = useLoadAudio({ src: '/audio/coin.mp3', key: 'coin' });
    const pickup = useSound(coin);
    listen(chest, { onClick: () => pickup.play() });
    return createScene();
};
Ver el código · hooks/loaders/use_load_audio.ts:56

useLoaderfunctionhooknacatamalon

useLoader(assets?: typeOperator) => TLoader

Keeps count of what a scene is loading, for a loading bar or to wait before changing scene.

  • useLoader([hero, tiles]): exactly those.
  • useLoader(): everything this scene asks for with useLoadTexture, including what its body asks for after this line. Counted once the body is over.

The scene keeps drawing while it loads, so a loading bar made of sprites without a texture is on screen from the first frame. Must be called inside a scene body, like every hook.

A clarification: If you use useLoader() with no arguments, it will track all assets requested by the scene, including those requested after the call. If you use with a specific list of assets, it will only track those and ignore any others requested by the scene.

Parámetros

assetsopcionaltypeOperator

What to count. Left out, everything the scene asks for.

Ejemplo

export const Loading: TSceneFn = () => {
    const scene = useScene();
    const loader = useLoader([
        useLoadTexture({ src: '/assets/hero.png', key: 'hero' }),
        useLoadTexture({ src: '/assets/tiles.png', key: 'tiles' }),
    ]);
    const bar = createSprite({ width: 0, height: 8, transform: { x: 60, y: 112 } });
    useUpdate(() => {
        bar.width = loader.progress * 200;
        if (loader.done) scene.change('Level');
    });
    return createScene();
};
Ver el código · hooks/loaders/use_loader.ts:43

useLoadFontfunctionhooknacatamalon

useLoadFont(options: TUseLoadFontOptions) => TFont

Loads a bitmap font: an image with the characters drawn in it, and a file saying where each one is.

You get the font back at once, still loading. Hand it to createText straight away: the text appears by itself when the font arrives, and useLoader counts it like any other asset.

Asking for the same font twice, in this scene or another, gives back the one already loaded.

Parámetros

optionsTUseLoadFontOptions

json and atlas, the two files of the font, and an optional key.

Ejemplo

export const Title: TSceneFn = () => {
    const font = useLoadFont({
        json: '/fonts/arcade/arcade.json',
        atlas: '/fonts/arcade/arcade.png',
    });

    createText({ text: 'PRESS START', font, transform: { x: 16, y: 16 } });

    return createScene();
};
Ver el código · hooks/loaders/use_load_font.ts:57

useLoadGltffunctionhooknacatamalon

useLoadGltf(options: TUseLoadGltfOptions) => TGltfModel

Loads a model made somewhere else: something sculpted in Blender, bought in a pack, exported from anywhere that writes glTF.

Both kinds of the format are read, and you do not have to know which you have. One is a description in text with its numbers and pictures in files beside it, the other is all of it in a single file, and which you were given is an accident of the button somebody pressed. The file is asked, not its name.

You get the model back at once, still loading. Hand it to createModel straight away: it appears by itself when the file arrives, and useLoader counts it like any other asset.

A file is usually several pieces, each with its own colour or picture: a vehicle is a body, glass and tyres. All of them come, and createModel draws them as one thing you move with one placement.

Asking for the same model twice, in this scene or another, gives back the one already loaded, and its shapes are on the graphics card once however many of it you put in the world.

Parámetros

optionsTUseLoadGltfOptions

Where the model is, and how to read it.

Ejemplo

export const Level: TSceneFn = () => {
    useCamera3d({ projection: 'perspective', z: 6 });
    useLight({ intensity: 1 });

    const tower = useLoadGltf({ src: '/models/tower.glb' });
    const placed = createModel({ model: tower });

    useUpdate((delta) => {
        placed.transform.rotationY += delta * 0.5;
    });

    return createScene();
};
Ver el código · hooks/loaders/use_load_gltf.ts:82

useLoadLutfunctionhooknacatamalon

useLoadLut(options: TUseLoadLutOptions) => TLut

Loads a colour grading table.

Both shapes a table comes in are read here and end up the same: a .cube is text written by a grading tool, a strip is a picture of the same numbers, and which one you have is a fact about where it came from rather than about what it does.

Handed back at once and filled in when the file lands. Until then an effect grading with it shows the frame unchanged.

Parámetros

optionsTUseLoadLutOptions

Where the file is, and what to keep it under.

Ejemplo

const evening = useLoadLut({ src: '/luts/evening.cube' });
usePostProcess({ ...lutGrade({ amount: 0.8 }), lut: evening });
Ver el código · hooks/loaders/use_load_lut.ts:48

useLoadPackfunctionhooknacatamalon

useLoadPack(options: TUseLoadPackOptions) => TLoadedPack

Loads a pack: boxes and scenes somebody made in another project, with everything they need.

A pack is a folder (what installing a .nacapack writes) and this reads it: its manifest, and the document of each box and scene it offers, with every picture and sound they use found inside the pack's folder, wherever you serve it. Hand it to createPack to place what it offers.

The input actions its scripts read are added to the game when it lands, if the game does not have them already. Its scripts are code, which a loader cannot bring: import the pack's <name>.pack.ts once and they are registered.

Handed back at once and filled in when it lands, like every other asset, and useLoader counts it. Asking for the same pack twice, in this scene or another, gives back the one already loaded.

Parámetros

optionsTUseLoadPackOptions

Where the pack is, and what to keep it under.

Ejemplo

const Plaza: TSceneFn = () => {
    const signs = useLoadPack({ src: '/packs/signpost' });
    createPack({ pack: signs, box: 'Signpost', transform: { x: 100, y: 120 } });
    return createScene();
};
Ver el código · hooks/loaders/use_load_pack.ts:55

useLoadPalettefunctionhooknacatamalon

useLoadPalette(options: TUseLoadPaletteOptions) => TPalette

Loads a set of colours for an effect to match a frame against.

Handed back at once and filled in when the file lands, like every other asset. Until then an effect matching against it shows the frame unchanged, so a palette that is slow to arrive costs you the palette and never the picture.

Parámetros

optionsTUseLoadPaletteOptions

Where the file is, and what to keep it under.

Ejemplo

const nes = useLoadPalette({ src: '/palettes/nes.palette' });
usePostProcess({ ...paletteMatch(), palette: nes });
Ver el código · hooks/loaders/use_load_palette.ts:45

useLoadParticlesfunctionhooknacatamalon

useLoadParticles(options: TUseLoadParticlesOptions) => TParticlesFile

Loads an effect: what a puff of smoke or a shower of sparks is made of.

The file is the effect and it is shared: three torches in a level are one document, read once, with one picture behind it. Each of them is its own emitter with its own particles, its own clock and its own run of luck.

Handed back at once and filled in when it lands, like every other asset. Until then an emitter following it draws nothing, which is what lets a scene appear before its effects do.

Parámetros

optionsTUseLoadParticlesOptions

Where the file is, and what to keep it under.

Ejemplo

const fire = useLoadParticles({ src: '/effects/fire.particles' });
createParticles({ effect: fire, transform: { x: 150, y: 250 } });
Ver el código · hooks/loaders/use_load_particles.ts:48

useLoadShaderfunctionhooknacatamalon

useLoadShader(options: TUseLoadShaderOptions) => TShader

Loads a shader written in a file, so an effect can live beside the game instead of inside it.

Hand what comes back to createMaterial({ effect }). It arrives still loading, and anything built on it draws with the built-in shader until it lands: a scene is never held up waiting for an effect, it simply gets the effect a moment late.

The file says which family it is for and what knobs it has, so the scene repeats neither.

A file ending in .shader is a shader drawn as nodes rather than written, and it is loaded the same way: it brings both languages with it, so it never takes a glslSrc.

Parámetros

optionsTUseLoadShaderOptions

Where the file is, and what to keep it under.

Ejemplo

export const Level: TSceneFn = () => {
    const crt = useLoadShader({ src: '/shaders/crt.wgsl' });
    const texture = useLoadTexture({ src: '/assets/hero.png' });

    createSprite({ texture, material: createMaterial({ effect: crt, uniforms: { lines: 80 } }) });

    return createScene();
};
Ver el código · hooks/loaders/use_load_shader.ts:65

useLoadTexturefunctionhooknacatamalon

useLoadTexture(options: TUseLoadTextureOptions) => TTexture

Loads an image to draw with, and hands it back at once, still loading: a sprite made with it appears by itself when the file arrives, so nothing has to wait for it.

You can use this hook with a useLoader to track its loading progress.

Parámetros

optionsTUseLoadTextureOptions

Where the image is, and the name to keep it under (key), which a later createSprite({ key }) can find it by.

Ejemplo

export const Level: TSceneFn = () => {
    const hero = useLoadTexture({ src: '/assets/hero.png', key: 'hero' });
    createSprite({ texture: hero });
    return createScene();
};
Ver el código · hooks/loaders/use_load_texture.ts:48

TAudioCliptypenacatamalon

A sound asset, returned by useLoadAudio the moment it is asked for.

It is born 'loading' with no length, and the loader fills it in place once the file has been fetched and decoded. Anything holding it (a useSound) sees the change with no re-wiring, which is why it is filled in rather than replaced.

Everything but buffer is plain data. buffer is the decoded sound inside the browser's audio engine: runtime only, and null until it is ready, exactly like gpu in a texture.

Propiedades

type'audio'
keystring

What it is cached under in this game. The src unless a key was given.

srcstring

Where the file comes from.

durationnumber

How long it lasts, in seconds. 0 until it is 'ready'.

bufferAudioBuffer | null

The decoded sound. null while loading and after an error.

Ver el código · loaders/audio/types/t_audio_clip.ts:17

TChildEmittertypenacatamalon

Another effect a particle sets off when it is born or when it dies: the sparks a firework leaves.

src is another .particles, relative to this one, never an effect written inline: a child is an effect like any other, made, looked at and used again like one.

Propiedades

on'birth' | 'death'

When in a particle's life it goes off.

srcstring

The other file, relative to this one.

countnumber

How many of the child's particles each one sets off.

Ver el código · loaders/particles/types/t_particles_doc.ts:237

TFonttypenacatamalon

A bitmap font, returned by useLoadFont the moment it is asked for.

It is born 'loading' and fills itself in once both its description and its image have arrived. Texts made with it draw nothing until then, and appear on their own when it is ready.

Propiedades

type'font'
keystring

What it is cached under in this game. The description's path unless a key was given.

srcstring

Where the description file comes from.

textureTTexture

The image holding every character.

metaTFontMeta | null

The description, or null until it has arrived.

Ver el código · loaders/font/types/t_font.ts:66

TFontMetatypenacatamalon

A bitmap font's description file, exactly as it is written on disk.

Propiedades

namestring
glyphHeightnumber

How tall every character is, in pixels of the image.

trackingnumber

Extra pixels of the image between two characters, added after each one.

baselinenumber

How far down from the top of a character its baseline is.

atlasWidthnumber
atlasHeightnumber
charsTFontGlyph[]
Ver el código · loaders/font/types/t_font.ts:37

TGltfModeltypenacatamalon

A model loaded from a file, and everything it takes to draw it.

You get it back at once, still loading, and the pieces appear in parts when the file arrives. Hand it to createModel straight away: what it shows turns up by itself.

Propiedades

type'gltf'
keystring

What it is kept under in this game. The src unless a key was given.

srcstring
partsTGltfPart[]

Its drawable pieces, in the order the file lists them. Empty until it arrives.

skeletonsTSkeleton[]

The rigs it holds. Nearly always none or one, but a file is allowed more and a few do.

A model holds them rather than a part, because a clip is free to move bones of several at once and playing it has to reach all of them.

clipsRecord<string, TSkeletalClip>

The movements it came with, by name. Empty for a model nobody animated.

Ver el código · loaders/gltf/types/t_gltf_model.ts:63

TGltfNodeInfotypenacatamalon

One piece of a glTF file's tree, said with the engine's words: the shape a tool turns into a box when it brings a model in.

Propiedades

namestring

The piece's name, which is also how a model asks for it. Empty when the file names nothing: such a piece can still group others, but nothing can point at it, so a tool must not give it a mesh.

transformTTransform3d

Where it sits relative to the piece above it.

hasMeshboolean

Whether it has something to draw. One that does not only groups the ones below it.

skinnedboolean

Whether a rig deforms its mesh. A rigged piece has to come in as one box with everything below it: there the bones own the placements, and splitting it would leave two owners writing the same ones.

childrenTGltfNodeInfo[]
Ver el código · loaders/gltf/types/t_gltf_node_info.ts:11

TGltfParttypenacatamalon

One drawable piece of a model: a shape and the surface it wears.

A model file is one piece surprisingly rarely. A vehicle is a body, glass and tyres; a character is skin, hair and clothes. Each of those is a piece here because each wears a different surface, and a surface is the thing that cannot be shared: merging them would mean choosing one picture for all of it.

Propiedades

namestring

The name of the piece it came from, or '' when it was never given one.

materialstring

The name of the surface it wears, or ''. It is often the only thing telling two pieces of one model apart: a windscreen and the body around it are usually the same piece of the file and differ only in this.

geometryTGeometry
textureTTexture | null

The picture on it, or null for a plain coloured surface.

tintTColor
emissiveTColor
transparentboolean

Whether the file says it is seen through, whatever its colour's alpha: a picture with see-through parts is the usual reason, and nothing else would tell.

wrap{ u, v }

What its picture does past its edge, as the file says: repeating, unless it says otherwise.

skeletonTSkeleton | null

The bones that move it, or null when nothing does.

Ver el código · loaders/gltf/types/t_gltf_model.ts:20

TLoadedAtlastypenacatamalon

A sheet described by a file: the image, how it is cut, and the runs of frames over it.

It is a sheet and a load at once. Once it is 'ready' it is exactly what createSprite and useSpriteAnimation take, and until then it is something useLoader counts, like an image.

Propiedades

type'atlas'
keystring

What it is cached under: the key given, or the path.

srcstring

Where the file is.

statusTLoadStatus

How it is doing. A sheet that failed reports 'error' and slices nothing.

textureTTexture

The image the file names, loaded with it.

columnsnumber

How many frames across. 0 until the image has landed and the grid can be worked out.

rowsnumber

How many frames down. 0 until then.

framesnumber

How many frames in total. 0 until then.

rectsopcionaltypeOperator

The window of every frame, as the file cuts the image. Filled in with the grid.

namesopcionalRecord<string, number>

Where each named frame of a packed sheet sits in the count, by name. A map's tile can name its frame instead of counting to it, and this is what turns the name into the place.

sequencesRecord<string, TAnimationClip>

The runs the file declares, by name, ready for useSpriteAnimation.

Ver el código · loaders/atlas/types/t_loaded_atlas.ts:17

TLoadedPacktypenacatamalon

A pack, as useLoadPack hands it back: what it offers, ready to be placed with createPack.

It is a definition and not something in the world. It has no position and no state of its own, the same as a model file: each copy made from it with createPack has its own place and its own settings, and the pack is not changed by any of them.

Handed back at once, still loading, and filled in when its manifest and the documents it offers land. Until then boxes and scenes are empty.

Propiedades

type'pack'
keystring

What it is cached under: the key given, or the folder.

srcstring

The pack's folder, always ending in /. Everything in it is found from here.

statusTLoadStatus

How it is doing. A pack that failed reports 'error' and places nothing.

namestring

Its name, from its manifest. Empty until it lands.

versionstring

Its own version, from its manifest.

exports{ boxes, scenes }

What it offers, by name. Either list may be empty: a pack of assets offers neither.

boxesRecord<string, TSceneDoc>

The documents of the boxes it offers, by name, with their paths already found in its folder.

scenesRecord<string, TSceneDoc>

The documents of the scenes it offers, by name, the same way.

actionsTActionMap

The input actions its scripts read, with the bindings they came with.

Ver el código · loaders/pack/types/t_loaded_pack.ts:19

TLoadertypenacatamalon

How a batch of loads is doing, returned by useLoader. Plain data, updated in place as each asset settles, so a scene reads it in useUpdate to drive a progress bar or move on.

Propiedades

totalnumber

How many assets the batch tracks.

loadednumber

How many of them have settled, 'ready' or 'error'.

progressnumber

loaded / total, from 0 to 1. 1 for an empty batch.

doneboolean

true once every asset has settled. An error counts as settled: waiting for it would be forever.

Ver el código · loaders/types/t_loader.ts:9

TLoadStatustypenacatamalon

TLoadStatus: 'loading' | 'ready' | 'error'

Where an asset is in its load. 'loading' from the moment it is asked for, then exactly one of 'ready' (usable) or 'error' (it will never be usable), and it never goes back.

Ver el código · loaders/types/t_load_status.ts:9

TLuttypenacatamalon

A grading table, whatever shape its file had.

One layout, whichever it came from. A .cube is text and a strip is an image, but by the time anything downstream looks at it there is only the strip: N slices side by side, each N by N. Red runs across within a slice, green down it, and blue picks which slice. That is the layout every engine uses, so a table exported for another one drops straight in.

Propiedades

type'lut'
keystring

What it is kept under in this game. The src unless a key was given.

srcstring
sizenumber

How many steps a side: a 16 table is 16 by 16 by 16. 0 until it lands.

gpuITexture | null

The uploaded strip, size * size across and size down. null until it lands.

Ver el código · loaders/lut/types/t_lut.ts:16

TPalettetypenacatamalon

A palette asset, handed back the moment it is asked for and filled in when the file lands.

Its picture is one row of pixels, one per colour, which is how the card reads it: an effect asks how many there are and then for the nth, and neither question needs a second dimension.

Propiedades

type'palette'
keystring

What it is kept under in this game. The src unless a key was given.

srcstring
namestring

What the file called it, or an empty string until it lands.

colorsstring[]

The colours as written, in file order. Empty until it lands.

gpuITexture | null

The uploaded row. null while loading and after an error.

Ver el código · loaders/palette/types/t_palette.ts:40

TPaletteDoctypenacatamalon

A .palette file as it is written on disk.

Plain JSON, because a palette is the one part of this whole feature that is data rather than arithmetic: everything else the engine can work out, and these are colours somebody chose.

Propiedades

formatnumber
kind'palette'
namestring

What a person calls it. The file's name is its identity; this is only read.

colorsstring[]

The colours, as #rrggbb.

The order means nothing to the matching, which walks all of them anyway, and it is kept all the same because it is how whoever made the palette arranged it.

Ver el código · loaders/palette/types/t_palette.ts:14

TParsedShadertypenacatamalon

What reading a shader file got out of it.

The same shape whichever way the file was authored, so whatever learns to write shader files next plugs in here without anything downstream noticing.

Propiedades

shaderTMaterialShader

Which family the file is for, from its @shader line, or 'sprite2d' if it had none.

fragmentstring | null
vertexstring | null
fragmentGlslstring | null
vertexGlslstring | null
uniformsTUniformValues

The knobs it declared, with the values it gave them.

uniformSigTUniformSignature

What kind each of those is, straight from the declaration rather than guessed.

Ver el código · loaders/shader/types/t_parsed_shader.ts:13

TParticlesBoundstypenacatamalon

How far an effect reaches: a box in the emitter's own space, centred where it says, because a fountain reaches up and dust reaches sideways.

Said, and not enforced. Nothing is stopped at its faces and nothing is left undrawn because of it: an effect that outgrows its box has the wrong box. It is here so a tool can draw it and a renderer could one day skip an effect that is nowhere near the screen. A flat effect leaves z at zero on both.

Propiedades

center{ x, y, z }

The middle of the box.

size{ x, y, z }

Its whole size on each axis, not half of it.

Ver el código · loaders/particles/types/t_particles_doc.ts:216

TParticlesDoc2dtypenacatamalon

A flat .particles file, read: pixels, with +y down, like everything else in the plane.

Normalized as it is read, which is what lets everything downstream be a plain walk with no guards: the curves come out sorted with their t inside 0 to 1, a bare number has been widened into a range, and a range somebody wrote backwards has been turned round rather than refused.

Propiedades

formatnumber
kind'particles2d'
texturestring | null

The picture every particle shows, relative to the file rather than to the page.

atlasstring | null

A sheet to take the picture from instead, relative to the file. Read and written back, and not drawn yet: this version shows the particles without a picture when it is given one.

framenumber | string | null

Which frame of that sheet, by its place or its name. At most one of this and anim.

animstring | null

A run of that sheet played over each particle's whole life. At most one of this and frame.

maxnumber

How many may be alive at once. Asked for once and never grown.

worldSpaceboolean

Whether a particle keeps living where it was born when the emitter moves on.

true, the default, is what a trail of smoke behind a moving thing needs. false drags the whole cloud along with the emitter, which is what a magical aura wants.

emissionTEmissionDoc
directionnumber

The middle of the direction they fly, in radians. 0 is to the right; with y downwards, up is -π/2.

spreadnumber

How wide that fan is, in radians. A whole turn is every direction at once.

lifeTParticleRange

How long they live, in seconds.

speedTParticleRange

How fast they set off, in pixels a second.

sizeTParticleRange

How big they are born, in pixels.

spinTParticleRange

How fast they turn, in radians a second.

gravity{ x, y }

A steady pull, in pixels a second squared. +y is down.

dampingnumber

How much of its speed a particle sheds each second, 0 to 1.

colorOverLifeTParticleColorStop[]
sizeOverLifeTParticleScaleStop[]
collisionTParticleCollision | null

What it does when it runs into a collider in the scene, or null to pass through everything.

trailTParticleTrail | null

The tail each particle leaves, or null for none.

boundsTParticlesBounds | null

How far it reaches, or null when nobody has said. See TParticlesBounds.

childrenTChildEmitter[]

The effects its particles set off.

unsupportedRecord<string, unknown>

Whatever else the file declared, kept exactly as written and not acted on by this version.

Keeping it is not the same mistake as inventing a field nobody reads: throwing it away would quietly rewrite somebody's file the first time a tool saved it.

Ver el código · loaders/particles/types/t_particles_doc.ts:264

TParticlesDoc3dtypenacatamalon

TParticlesDoc3d: Omit<TParticlesDoc2d, 'kind' | 'shape' | 'direction' | 'gravity'> & { kind, shape, direction, gravity }

A .particles file for three dimensions, read: world units, with +y up.

Everything but four fields reads as it does in the flat one. The four are the ones a dimension changes the meaning of: where they are born, which way they fly, which way they fall, and the kind that says so. Pixels and units differ by a factor of a hundred, so the two never share defaults.

Ver el código · loaders/particles/types/t_particles_doc.ts:368

TParticlesFiletypenacatamalon

A .particles file, on its way in or already here.

Kept apart from the emitter that follows it, and that split is the whole reason this type exists: three torches in a level are three emitters, each with its own particles, its own clock and its own stream of chance, all reading one document. Folding the two together is what makes three torches parse three files and upload three copies of the same picture.

Like a shader and unlike a texture, it keeps a list of who is waiting on it. A picture can be handed to a sprite and that is enough, because the sprite hands it straight to the card. An effect cannot: an emitter has to size its particles from the document, so when the bytes land they have to reach everything already built against them.

Propiedades

type'particles-file'
keystring

What it is kept under in this game. The src unless a key was given.

srcstring
docTParticlesDoc | null

What the file said, or null until it lands.

textureTTexture | null

The picture, loaded through the game's own cache so two effects sharing one fetch it once.

boundTParticles | TParticles3d[]

The emitters built on this file, filled in when it lands. Never written out.

childrenTParticlesFile | null[]

The files of the effects its particles set off, one per entry of doc.children, in the same order. null for one that was refused (a file that leads back to itself, or one too deep).

Ver el código · loaders/particles/types/t_particles_file.ts:24

TParticleTrailtypenacatamalon

A tail drawn behind each particle, out of where it has just been.

It is more of the same particle and not a ribbon: copies of it, smaller and fainter towards the end, which is how a trail was drawn in that era and needs nothing the draw does not already have. length is in copies because that is what it costs: max × length more of them, set aside once.

Propiedades

lengthnumber

How many of its last places each particle keeps.

widthnumber

How wide, against the particle's own size.

fadeboolean

Whether it also fades towards the end, and not only narrows.

Ver el código · loaders/particles/types/t_particles_doc.ts:188

TShadertypenacatamalon

A shader written in a file, on its way in or already here.

The file holds the hooks and the knobs and says which family it is for, so the scene that uses it repeats none of that. One file can be shared by any number of materials, and is fetched once.

It keeps a list of who is following it, which is the one thing that makes it unlike a texture. A texture is handed to a drawing and that is enough, because the drawing hands the texture straight to the card. A shader is not: the card compiles from the source, so when the bytes finally land they have to be poured into every material that was already built against it.

Propiedades

type'shader'
keystring

What it is kept under in this game. The src unless a key was given.

srcstring

Where the WGSL comes from.

glslSrcstring | null

Where the GLSL comes from, when it was written in a second file instead of the same one.

shaderTMaterialShader

Which family the file declared, or 'sprite2d' when it did not say.

fragmentstring | null

The fragment hook in WGSL, or null if the file defines only a vertex one.

fragmentGlslstring | null

The same hook in GLSL, or null when the author wrote no GLSL half.

vertexstring | null

The vertex hook in WGSL.

vertexGlslstring | null

The same, in GLSL.

uniformsTUniformValues

The knobs the file declared, with the values it gave them.

uniformSigTUniformSignature

What kind each of those is.

boundTShaderTarget[]

Everything built on this file, which is filled in when it lands. Never written out.

Materials and screen-wide effects both, because the two want the same thing from a file and neither can be built from it until the bytes are here.

Ver el código · loaders/shader/types/t_shader.ts:20

TSpriteAtlastypenacatamalon

One image holding many pictures in a grid, and the arithmetic to point at any of them.

A grid rather than a list of rectangles, because that is what a sprite sheet is and because it needs no pixel sizes: the frames are fractions of the image, so an atlas works from the moment it is described, before the image has even arrived.

Frames are numbered from 0, left to right and then top to bottom, the order a sheet is drawn in.

Propiedades

textureTTexture

The image itself. Every frame is a window into it.

columnsnumber

How many frames across.

rowsnumber

How many frames down.

framesnumber

How many there are in total, which is what a frame number has to stay under.

rectsopcionaltypeOperator

The window of every frame, for a sheet that is not an even grid of the whole image: one read from a file with margins, gaps, a cell size that does not divide the image, or rectangles of its own. Left out, the grid above is the whole answer.

Ver el código · atlas/types/t_sprite_atlas.ts:16

TTexturetypenacatamalon

A texture asset, returned by useLoadTexture the moment it is asked for.

It is born 'loading' with no size, and the loader fills it in place once the image has been fetched, decoded and uploaded. Anything holding it (a sprite) sees the change on its next frame with no re-wiring, which is the whole reason it is mutated rather than replaced.

Everything but gpu is plain data. gpu is a handle into the renderer's memory: runtime only, meaningless to anyone but the backend that made it, and null until the upload.

Propiedades

type'texture'
keystring

What it is cached under in this game. The src unless a key was given.

srcstring

Where the image comes from.

widthnumber

In pixels. 0 until it is 'ready'.

heightnumber

In pixels. 0 until it is 'ready'.

gpuITexture | null

The uploaded texture. null while loading and after an error.

Ver el código · loaders/texture/types/t_texture.ts:18

TUseLoadAtlasOptionstypenacatamalon

What useLoadAtlas is asked for.

Propiedades

srcstring

Where the .atlas file is.

keyopcionalstring

What to remember it under, so another scene can ask for the same sheet. Defaults to src.

Ver el código · hooks/loaders/use_load_atlas.ts:13

TUseLoadAudioOptionstypenacatamalon

What useLoadAudio is asked for. Named fields rather than two bare strings, which would be too easy to swap.

Propiedades

srcstring

Where the sound file is. Anything the browser can play: .mp3, .ogg, .wav.

keyopcionalstring

What to cache it under, so another scene can reach the same sound. Defaults to src.

Ver el código · hooks/loaders/use_load_audio.ts:15

TUseLoadFontOptionstypenacatamalon

Where a bitmap font comes from.

Propiedades

jsonstring

The font's description file: where each character sits in the image.

atlasstring

The image with every character drawn in it.

keyopcionalstring

What to call it in this game. Default: the description's path.

Ver el código · hooks/loaders/use_load_font.ts:13

TUseLoadGltfOptionstypenacatamalon

Where a model comes from, and how to read it.

Propiedades

srcstring

The model file: either kind, .gltf or .glb.

nodeopcionalstring

One named piece of the file and whatever hangs beneath it, instead of all of it. For taking one turret out of a file holding a whole fortress.

shadingopcionalTShading

How its surfaces are made to face. 'auto', the default, keeps what the file says. 'smooth' works them out afresh so the surface shades evenly across; 'flat' gives every triangle a hard edge, which is the look of the era and of a model built to have it.

texturesopcionalboolean

false loads no pictures, leaving each piece in its plain colour. Default true.

keyopcionalstring

What to call it in this game. Default: src, or src and the piece when one is named.

Ver el código · hooks/loaders/use_load_gltf.ts:13

TUseLoadLutOptionstypenacatamalon

What useLoadLut is asked for.

Propiedades

srcstring

Where the table is: a .cube file, or a strip image.

keyopcionalstring

What to keep it under, so another scene can reach the same one. Defaults to src.

Ver el código · hooks/loaders/use_load_lut.ts:14

TUseLoadPackOptionstypenacatamalon

What useLoadPack is asked for.

Propiedades

srcstring

The pack's folder: where pack.json is. With or without the last /.

keyopcionalstring

What to keep it under, so another scene can reach the same one. Defaults to src.

Ver el código · hooks/loaders/use_load_pack.ts:14

TUseLoadShaderOptionstypenacatamalon

What useLoadShader is asked for.

Propiedades

srcstring

Where the shader is. Its WGSL half, which is the one that has to exist.

glslSrcopcionalstring

Where its GLSL half is, when it was written in a second file instead of after a // @glsl line in the same one.

Two files work, and one is usually better: with two, the header is written twice and the halves are free to drift. The loader reads both and refuses them if they disagree, so the drift is caught, but not writing it twice is simpler than catching it.

keyopcionalstring

What to keep it under, so another scene can reach the same one. Defaults to src.

Ver el código · hooks/loaders/use_load_shader.ts:14

TUseLoadTextureOptionstypenacatamalon

What useLoadTexture is asked for. Named fields rather than two positional strings, which would be too easy to swap.

Propiedades

srcstring

Where the image is.

keyopcionalstring

What to cache it under, so another scene can reach it with createSprite({ key }). Defaults to src.

Ver el código · hooks/loaders/use_load_texture.ts:14