Sprites
Back to the reference

Sprites

The 2D drawable and its atlas.

14 symbols

ATLAS_FORMATvariablenacatamalon

ATLAS_FORMAT: 1

The version of the .atlas format this engine writes, and the newest it reads. It only goes up for a change an older reader could not survive: a new optional field does not move it.

View source · atlas/document/atlas_format.ts:9

createSpritevariablenacatamalon

createSprite: TCreateSprite

Puts a picture in the scene: an image from useLoadTexture, a frame of a sheet, or a plain coloured rectangle when it has neither.

It is placed by its anchor, its middle unless you say otherwise, so transform: { x: 160, y: 120 } centres it there. Everything about it is a plain field you can change at any time (hero.transform.x += 1, hero.tint = red), and the next frame shows it.

Example

export const Level: TSceneFn = () => {
    const texture = useLoadTexture({ src: '/assets/hero.png' });
    const hero = createSprite({ texture, transform: { x: 160, y: 120 } });
    // No picture: a coloured rectangle, placed by its top-left corner.
    createSprite({ width: 320, height: 16, tint: getColor('#3a2a1a'), anchor: { x: 0, y: 0 }, transform: { y: 224 } });

    useUpdate((delta) => {
        hero.transform.rotation += delta;
    });

    return createScene();
};
View source · gameobjects/sprite/create_sprite.ts:113

parseAtlasDocfunctionnacatamalon

parseAtlasDoc(value: unknown, src: string) => TAtlasDoc

Reads an .atlas file, already parsed from JSON, and checks all of it at once.

All of it and at once, rather than whatever a sprite happens to touch, because tools read these files as much as games do: an editor has to say "this file is broken, here" while its author is looking at it. Every message names src, since a project has many sheets and this is the last place that knows which one it was.

Parameters

valueunknown

The file's contents, parsed from JSON.

srcstring

Where it came from, for the messages.

View source · atlas/document/parse_atlas_doc.ts:62

TAtlasDoctypenacatamalon

What an .atlas file holds: which image, how it is cut, and the named runs its frames make.

Cut one of two ways and never both: a regular grid, or a packed table of rectangles, which is what a packing tool writes.

Properties

formatnumber
kind'atlas'
texturestring

The image, relative to the .atlas file.

gridoptionalTAtlasGridSpec
packedoptionalRecord<string, TAtlasPixelRect>

Frame name to rectangle, in the order the frames are numbered.

sequencesoptionalRecord<string, TAtlasSequenceDoc>
View source · atlas/document/types/t_atlas_doc.ts:95

TAtlasDocFrametypenacatamalon

One frame of a sheet as a document cuts it: the window into the image in 0-1, and its size in pixels, with its name when the sheet is packed.

Properties

nameoptionalstring
uvOffset{ x, y }
uvScale{ x, y }
widthnumber
heightnumber
View source · atlas/document/types/t_atlas_doc.ts:118

TAtlasGridSpectypenacatamalon

How a sheet laid out in a regular grid is cut: the size of a cell, or how many there are, and the gaps round and between them.

Give the cell size or the count on each axis, and the other is worked out from the image. That is what lets the same file describe a sheet whose size is not a whole number of cells, a common thing in sheets made by hand: whatever is left over at the edge is simply not a frame.

Properties

frameWidthoptionalnumber

Width of one cell in pixels.

frameHeightoptionalnumber

Height of one cell in pixels.

columnsoptionalnumber

Cells across. Worked out from the image when left out.

rowsoptionalnumber

Cells down. Worked out from the image when left out.

marginoptionalnumber

Empty pixels round the whole sheet. Default 0.

spacingoptionalnumber

Empty pixels between two cells. Default 0.

countoptionalnumber

How many cells are frames, counting row by row, for a last row that is not full.

View source · atlas/document/types/t_atlas_doc.ts:13

TAtlasSequenceDoctypenacatamalon

A named run of frames: which ones, how fast, and what comes after.

Properties

framesnumber | string[]

The frames to play in order: numbers in a grid, names in a packed sheet, mixed freely. Repeats are allowed.

fpsoptionalnumber

Frames per second. Default 12.

loopoptionalboolean

Starts again at the end. Default true; false rests on the last frame.

nextoptionalstring

The run to play when this one ends: a punch that drops back to standing. Only means something with loop: false, since a run that loops never ends.

In the file and not in the script that starts the punch, because what follows a punch is a decision about the animation, and one written into code makes retiming a character a code change. A name no run answers to is said once and the run rests on its last frame.

View source · atlas/document/types/t_atlas_doc.ts:60

TCreateSpritetypenacatamalon

TCreateSprite: (options: TSpriteOptions & { width, height }) => TSprite & { width, height }

The two ways to call createSprite. Given a width and a height (a coloured rectangle, or a picture drawn at a size of its own), the sprite that comes back has them as numbers, so paddle.width can be used in sums straight away. Given neither, they stay optional: the size is the picture's, and it is not known until the picture has loaded.

View source · gameobjects/sprite/create_sprite.ts:77

TSpriteOptionstypenacatamalon

What createSprite is asked for: a picture (texture, key or atlas), its size, where it goes and how it looks. All of it is optional.

Properties

materialoptionalTSpriteMaterial

An effect of its own, from createMaterial. Omitted is the built-in shader.

uniformsoptionalTUniformValues

This sprite's own values for that material's knobs, laid over the material's own.

widthoptionalnumber

Omitted: the texture's width once it has loaded.

heightoptionalnumber

Omitted: the texture's height once it has loaded.

transformoptionalPartial<TTransform2d>

Where it is, how it is turned and how big. Only what is given: the rest is no turn and a scale of 1, so { x, y } is enough. Copied, so the object handed in stays the caller's.

textureoptionalTTexture

A texture from useLoadTexture. Wins over key.

keyoptionalstring

The key a texture was loaded under, for a sprite built where the record is not at hand.

tintoptionalTColor
anchoroptional{ x, y }

Which point of the sprite sits on its transform, in 0-1 of its own size: { x: 0.5, y: 0.5 } is its middle and the default, { x: 0.5, y: 1 } the middle of its bottom edge (a character standing on a floor), { x: 0, y: 0.5 } its left edge (a bar that grows to the right). Rotation and scale happen around it.

atlasoptionalTSpriteAtlas

A sheet from createSpriteAtlas. It supplies the image and, with frame, which part of it to show. Anything given explicitly (texture, uvOffset, uvScale) wins over it.

frameoptionalnumber

Which frame of atlas to show, numbered from 0. Ignored without an atlas. Default 0.

uvOffsetoptional{ x, y }

Shows only part of the texture: where the window starts, in 0-1 across the image. Comes with uvScale, and both together are how one image holds many frames.

uvScaleoptional{ x, y }

How big that window is, in 0-1: { x: 0.5, y: 1 } is half the width, full height.

flipXoptionalboolean

Shows the picture mirrored left to right, which is how one drawing covers a character facing either way. It mirrors what is shown and not where it is: the sprite stays exactly where it was, and so does the place it can be touched.

flipYoptionalboolean

The same top to bottom.

visibleoptionalboolean

Whether it is drawn. Default true. false makes it straight away hidden, which is how a set of them is prepared in advance and shown one at a time.

smoothoptionalboolean

Overrides the game's smooth for this sprite alone: false keeps pixel art crisp when it is scaled up, true blends between texels.

zIndexoptionalnumber

Which sprites it is drawn in front of, within its own scene: higher numbers go on top, and negatives are allowed. Sprites with the same number keep the order they were created in. Default 0. It can be changed at any time and takes effect on the next frame drawn.

onPointerOveroptionalTPointerListener

Called when the mouse or a finger comes over this sprite. Only sprites with at least one of these events count when deciding what is under the pointer, so a decoration on top does not steal them.

onPointerOutoptionalTPointerListener

Called when the pointer stops being over this sprite, or leaves the game.

onPointerMoveoptionalTPointerListener

Called when the pointer moves while over this sprite.

onPointerDownoptionalTPointerListener

Called when a button is pressed, or a finger touches, over this sprite.

onPointerUpoptionalTPointerListener

Called when a button is released, or a finger lifts, over this sprite.

onClickoptionalTPointerListener

Called when this sprite is pressed and released without leaving it: what a button does. Pressing on it and releasing somewhere else does not count. The cursor turns into a hand over it.

View source · gameobjects/sprite/types/t_sprite_options.ts:15

TSpriteTexturetypenacatamalon

A picture that part of a scene is drawn into instead of the screen: a screen inside the game, a monitor, a handheld's display.

It sits on the object whose contents it shows. Everything on that object and under it is drawn into texture every frame, in the picture's own pixels, and anything else can show texture the way it shows a loaded image. The object is where the picture's world ends: a camera asked for in there belongs to the picture, and a lamp in there lights only the picture.

Plain data like every record, apart from texture.gpu, which is the renderer's.

Properties

type'sprite-texture'
idstring
widthnumber

In pixels. Also how wide the world inside is, before any camera.

heightnumber

In pixels. Also how tall the world inside is, before any camera.

seesTSpriteTextureSees

What is drawn into it. 'inside': only what is on its object and under it, a world of its own. 'scene': the models of the world around it as well, seen from its own camera, which is a security camera and a monitor showing it.

backgroundTColor

What the picture is cleared to every frame, behind everything drawn into it.

textureTTexture

The picture itself, ready from the first frame and found in the game's textures by its key.

View source · gameobjects/sprite_texture/types/t_sprite_texture.ts:28

TSpriteTextureOptionstypenacatamalon

What createSpriteTexture is asked for.

Properties

widthnumber

In pixels, rounded down and at least 1.

heightnumber

In pixels, rounded down and at least 1.

seesoptionalTSpriteTextureSees

'inside', the default: only what the component draws, a world of its own. 'scene': the models and particles in depth of the world around it as well, seen from the component's own 3D camera (or the scene's, if it asks for none) and lit by the scene's lamps, with whatever the component draws on top. That is a security camera: the flat part of the scene, its sprites and its texts, is not in the room and is not seen.

backgroundoptionalTColor

What is behind everything drawn into it. Opaque black when left out. A transparent one lets whatever shows the picture be seen through the parts nothing covers.

keyoptionalstring

The name the picture is kept under, so a model can ask for it by name the way it asks for a loaded image. A new one of its own when left out.

Worth giving in a scene that restarts: the same name and size gets the same picture back instead of a new one each time.

View source · gameobjects/sprite_texture/types/t_sprite_texture_options.ts:11