Animation
Back to the reference

Animation

What moves over time: sprite frames, skeletons and their clips, and tweens.

31 symbols

getSpriteAnimationfunctionnacatamalon

getSpriteAnimation(sprite: TSprite) => TSpriteAnimation | null

The animator a sprite already has, or null when nothing animates it.

A sprite from a scene file can arrive already moving: the file says which run it starts on, and the scene started it. This is how a behaviour reaches that same animator to change the run, instead of making a second one that fights the first for the same sprite every frame. If more than one was made for a sprite, it is the last.

Parameters

spriteTSprite

The sprite to ask about.

Example

const punch = (self: TGameObject) => {
    const sprite = self.drawables.find((drawable) => drawable.type === 'sprite');
    const anim = sprite === undefined ? null : getSpriteAnimation(sprite);
    const keys = useKeyboard();

    useUpdate(() => {
        if (keys.justPressed('f')) anim?.play('punch');
    });
};
View source · hooks/animation/get_sprite_animation.ts:47

useMotionfunctionhooknacatamalon

useMotion(motion: TMotionDoc | TMotionFile, options: TMotionOptions) => TMotionHandle

Plays a motion on the scene this is called in: a .motion file of values moved over time by keys (a camera sweeping the field, a title coming in), made in an editor's motion panel.

It moves on the scene's own clock, a frame at a time, so it stops when the scene is paused and goes slower or faster with it. Each track finds its box by id, and by name when no box has that id; a track whose box or field is not there is warned about once and moves nothing. On the way, it plays the sounds, changes the scene and calls the marks it is played past.

A scene document plays one with a motion component; this is the same thing from code, for a behaviour that decides when.

Parameters

motionTMotionDoc | TMotionFile

A motion from useLoadMotion, or a TMotionDoc written in code.

optionsTMotionOptions

Whether it starts by itself, loops, and how fast.

Example

export const Intro: TSceneFn = () => {
    const intro = useMotion(useLoadMotion({ src: '/motions/intro.motion' }), { autoplay: true });
    intro.on('titleShown', () => console.log('the title is up'));
    intro.onEnd(() => console.log('over'));
    return createScene();
};
View source · hooks/motion/use_motion.ts:126

useSkeletalAnimationfunctionhooknacatamalon

useSkeletalAnimation(model: TAnimatable, options: TSkeletalAnimationOptions) => TSkeletalAnimation

Makes a placed model move: plays the movements its file came with, and eases between them.

A rigged model is a skin stretched over bones. A movement turns the bones, and the skin follows, which is why one model can walk, run and fall over without three copies of it existing.

It moves the model createModel gave back, and only that one. Every model placed from a file has bones of its own, so five enemies of one file can walk, jump and stand still each on their own, each with an animator of its own.

It can be asked for a movement before the file has arrived, which is the ordinary case: the model comes back still loading, so play is remembered and honoured the moment it shows up.

fade is what makes it look like a character rather than a demo. Asked to change movement over half a second, it turns the bones from where one has them to where the other does; cutting straight across snaps a leg from behind to in front in a single frame.

only plays a movement on part of the body, the rest carrying on with what it was doing: a second animator on the same model, its bones named, shows over the first. The last one made goes on top. With nothing playing it leaves those bones to the one below, and a movement that ends hands them back, eased by its fade.

Parameters

modelTAnimatable

The placed model, from createModel.

optionsTSkeletalAnimationOptions

Which movement to start on, and how it plays.

Example

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

    const file = useLoadModel({ src: '/models/fox.glb' });
    const fox = createModel({ model: file });
    const moves = useSkeletalAnimation(fox, { play: 'Walk', fade: 0.25 });

    const keys = useKeyboard();
    useUpdate(() => {
        if (keys.justPressed('Space')) moves.play('Run');
    });

    return createScene();
};

Example

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

    const hero = createModel({ model: useLoadModel({ src: '/models/hero.glb' }) });
    useSkeletalAnimation(hero, { play: 'run' });
    const top = useSkeletalAnimation(hero, { only: ['spine'], fade: 0.2, clips: { greet: { loop: false } } });

    const keys = useKeyboard();
    useUpdate(() => {
        if (keys.justPressed('Space')) top.play('greet');
    });

    return createScene();
};
View source · hooks/animation/use_skeletal_animation.ts:97

useSpriteAnimationfunctionhooknacatamalon

useSpriteAnimation(sprite: TSprite, options: TSpriteAnimationOptions) => TSpriteAnimation

Plays a sprite's pictures in order, so it walks, attacks or spins.

A sheet already holds every picture and a sprite already shows one of them: animating is deciding which one, and when. That is all this does, once per frame, so the renderer never learns that animation exists.

The sprite has to come from a sheet (createSprite({ atlas })), since that is where the frames are. Call it while the scene is being built, like every hook, and keep what it returns to change clips later.

Parameters

spriteTSprite

The sprite to animate.

optionsTSpriteAnimationOptions

The runs it knows, which one to start with, and how fast.

Example

declare const walk: TSpriteAtlas;
declare let hurt: boolean;

const enemy = createSprite({ atlas: walk, frame: 0, transform: { x: 80, y: 120 } });

const anim = useSpriteAnimation(enemy, {
    clips: {
        walk: { frames: [0, 1, 2, 3, 4, 5], fps: 12 },
        hit: { frames: [6, 7], fps: 20, loop: false },
    },
    play: 'walk',
});

useUpdate(() => {
    if (hurt) anim.play('hit');
});
View source · hooks/animation/use_sprite_animation.ts:61

useTweenfunctionhooknacatamalon

useTween() => TTweenStarter

Declares tweens: a number, or the fields of an object, going from one value to another over time, so something can slide in, grow, fade or bounce without you writing the arithmetic for it every frame.

useTween() animates nothing by itself: it gives you back a function that declares tweens. A tween declared does not move either. It waits, and moves each time you call its play(), as many times as you like: declared once while the scene is built, played on every hit.

  • Played again once it is over, it makes the same trip again from the same start. Fields moved by an amount move it again from wherever they are.
  • tween.chain(a, b, c) plays them one after another, and tween.all(a, b) at the same time. Both are tweens too, so one goes into the other. What goes into them is played by them: you play the chain, not its steps.

What is animated is a plain number. The tween gives it to you every frame in onUpdate and you put it wherever it belongs, which is why the same hook moves a sprite, widens a loading bar or mixes two colours. Or it is given a target and the path to its fields, and moves them itself.

Tweens belong to the scene that declared them: they freeze while it is paused, they run in slow motion when the game does, and they are gone when it leaves. There is nothing to clean up.

Example

export const Level: TSceneFn = () => {
    const hero = createSprite({ key: 'hero', transform: { x: 40, y: 112 } });
    const door = createSprite({ key: 'door', transform: { x: 280, y: 112 } });
    const coin = createSprite({ key: 'coin', transform: { x: 160, y: 90 } });
    const tween = useTween();

    // Up and down for ever, from the moment the scene starts
    tween({ target: coin, to: { transform: { y: 84 } }, duration: 0.6, ease: easeInOutSine, yoyo: true, loop: true }).play();

    // Declared once, played on every hit: two blinks and a step back at the same time
    const hurt = tween.all(
        tween({ target: hero, to: { tint: { a: 0 } }, duration: 0.08, yoyo: true, repeat: 3 }),
        tween({ target: hero, by: { transform: { x: -12 } }, duration: 0.2, ease: easeOutQuad }),
    );
    const keys = useKeyboard();
    useUpdate(() => {
        if (keys.justPressed('h')) hurt.play();
    });

    // One after another: the door opens, then the hero walks through
    tween.chain(
        tween({ target: door, to: { transform: { y: -40 } }, duration: 0.5 }),
        tween({ target: hero, to: { transform: { x: 300 } }, duration: 1 }),
    ).play();

    return createScene();
};
View source · hooks/tween/use_tween.ts:589

TAnimatabletypenacatamalon

Anything with bones and movements for them, which is all useSkeletalAnimation reads: a model placed from a file (createModel), or a body a plugin gives bones of its own.

model.clips are the movements it knows, by name, read every time so movements that arrive later can be played at once; model.status says whether they have all arrived (left out, they have). skeletons are the bones they turn: the animator writes each one's pose.

Properties

model{ clips, status }
skeletonstypeOperator
View source · hooks/animation/types/t_skeletal_animation.ts:16

TAnimationCliptypenacatamalon

One named run of frames: which pictures, how fast, and whether it starts again at the end.

Properties

framestypeOperator

The frames of the sheet to show, in order. They may repeat and go backwards.

fpsoptionalnumber

Frames per second. Default 12, which is the usual pace for hand-drawn movement.

loopoptionalboolean

Whether it starts again at the end. Default true. A repeat says how many times instead.

repeatoptionalnumber

How many extra times it runs after the first, as a tween's repeat: 2 shows it three times and then it ends, telling onEnd. Given, it decides, and with loop too it says so.

yoyooptionalboolean

Whether each time it runs again it comes back the other way, as a tween's yoyo: [0, 1, 2, 3] plays 0 1 2 3 2 1 0 1 2 3…, the ends shown once. A breath, a float, a pendulum, without drawing the way back. Marks are passed on the way there, not on the way back. Default false.

eventsoptionaltypeOperator

Moments inside the run worth being told about: the picture a blow lands on, a footstep.

at is the place in this run, counting from 0, not the number of the picture on the sheet. A run is allowed to show the same picture twice ([4, 5, 6, 5, 4]), and the two showings are not the same moment: one is the swing going out and the other is it coming back. Counting places is the only way to tell them apart.

nextoptionalstring

The run to play when this one ends, for one that does not loop: a punch that drops back to standing. A name there is no run for is said once, and the run rests on its last picture.

View source · hooks/animation/types/t_sprite_animation.ts:10

TClipEventtypenacatamalon

Something that happens at a point inside a movement, rather than at its end: the moment a sword becomes dangerous, a foot meets the ground, a spell leaves the hand.

It is a cue, not a consequence: the movement says when, and the game decides what that means. That split is what lets the same swing be a hit, a parry or a miss without the animation knowing which, and it is why nothing here names a function.

Used by both halves of the engine. What at counts differs, because the two kinds of movement are measured differently, and each says so where it is taken.

Properties

atnumber

Where in the movement it happens. Its unit is the one the movement is measured in.

namestring

What it is called, which is what the listener is handed.

View source · animation/types/t_clip_event.ts:16

TJointPosetypenacatamalon

Where one bone sits relative to the bone above it: a move, a turn and a size.

Kept as three separate things rather than one matrix because that is how animation writes it: a clip turns a shoulder without touching where it is, and two poses can only be mixed sensibly one part at a time.

Properties

t[number, number, number]
s[number, number, number]
View source · animation/types/t_skeleton.ts:14

TMotionAttachmenttypenacatamalon

A motion a box carries: its file and how it was asked to play. What a saved scene writes as a motion component; never where it had got to.

Properties

type'motion'
idstring
autoplayboolean
loopboolean | null

null for what the file says.

speednumber
View source · motion/types/t_motion.ts:87

TMotionDoctypenacatamalon

A .motion file: values of a scene moved over time by keys, and what happens on the way. What an editor's motion panel writes, and what useMotion (or a motion component) plays.

Movement placed by hand lives here rather than in a behaviour: a camera sweeping a field, a logo coming in, a menu opening. Movement that answers the game (a ball's flight, an enemy chasing) is a behaviour's, with useTween or the update.

Properties

format'nacatamalon-motion'
versionnumber
durationnumber

How long it lasts, in seconds. A key after it is never reached.

loopoptionalboolean

Whether it starts again from the beginning once it ends. Default false.

tracksTMotionTrack[]
eventsTMotionEvent[]
View source · motion/types/t_motion_doc.ts:176

TMotionEventtypenacatamalon

TMotionEvent: { t, kind, box, name, component } | { t, kind, scene, transition } | { t, kind, name }

Something that happens at a moment of a motion, once each time it is played past.

  • sound plays a sound, music or song a box carries, by the box and the component's id.
  • scene changes to another scene, covered by a transition if one is given.
  • mark only has a name: a behaviour listens for it with on(name, …) on the motion it plays.
View source · motion/types/t_motion_doc.ts:93

TMotionHandletypenacatamalon

The controls of a motion playing on a box, handed back by useMotion.

Properties

play
pause
resume
stop
seek
on
onEnd
timenumber

Where it is, in seconds from the beginning.

durationnumber

How long it lasts, 0 until the file is here.

playingboolean
View source · motion/types/t_motion.ts:36

TMotionKeytypenacatamalon

One key of a track: the value it has at a moment.

Properties

tnumber

When, in seconds from the start of the motion.

vnumber | boolean

What the value is then. A number moves towards the next key; true or false (whether something is seen) holds until the next key, since there is nothing between the two.

easeoptionalTMotionEase

The curve of the stretch that arrives at this key, from the one before. Default 'linear'. Ignored on the first key, which nothing arrives at.

View source · motion/types/t_motion_doc.ts:22

TMotionOptionstypenacatamalon

How useMotion is asked to play.

Properties

autoplayoptionalboolean

Starts as soon as the file is here. Default false.

loopoptionalboolean

Starts again from the beginning once it ends. Default: what the file says.

speedoptionalnumber

How fast it plays: 2 twice as fast, 0.5 at half speed. Default 1.

idoptionalstring

Its id, the one a saved scene writes it under. Made up when not given.

View source · motion/types/t_motion.ts:10

TMotionTracktypenacatamalon

One value moved over time: which box, which part of it, which field, and its keys.

A box is named the way the scene document names it, by its id, so the track and the box an editor shows are the same one whatever the box is called. The name is kept beside it for reading and as a second way in: a copy of a reusable box has another id each time it is placed.

Properties

boxstring

The box, by its id in the scene document. Empty for a track of a screen effect (post).

nameoptionalstring

Its name, for reading, and to find it by when no box has that id.

componentoptionalstring

One of its components, by id, when the field is the component's (a sprite's tint, a camera's zoom). Absent for the box's own placement.

postoptionalstring

One of the game's screen effects (its post chain), by its name, when the field is the effect's: uniforms.amount, or enabled. A screen effect belongs to the game and not to a box, so such a track names no box.

pathstring

The field, as a path of dots: x, scaleY, rotation on the box; zoom or transform.x on a camera; tint.a, visible, width on a picture or a text; uniforms.amount on a picture with a material (its own value, or its material's until it has one).

keysTMotionKey[]

In order of time, at least one.

View source · motion/types/t_motion_doc.ts:50

TMotionTransitiontypenacatamalon

The cover a scene event changes under: one of the engine's transitions, by name, how long it takes in seconds, and what that one is given in code. A file that says ms, as they did before, is read in milliseconds. The five whose names say cross or push go from one scene to the other with no cover between, so they take no colour.

Each field past duration belongs to the transitions named beside it, and a file that gives one to another is refused: a direction on a fade would be a choice somebody made that does nothing.

Properties

type'fade' | 'wipe' | 'iris' | 'pixelate' | 'dissolve' | 'crossfade' | 'push' | 'crossWipe' | 'crossIris' | 'crossDissolve'
durationoptionalnumber

Seconds, covering and uncovering together, or crossing. Left out, what the transition takes in code when it is not told, and 0.6 for a dissolve and a cross dissolve.

coloroptionalTColor

Every one that covers: what the screen is covered with. Black unless the file says.

easeoptionalTMotionEase

Every one: the curve each half moves along, or the one run of one that crosses, by the name a key's ease uses. In a straight line unless the file says.

directionoptionalTWipeDirection

A wipe and a cross wipe: which way the edge travels. A push: which way both scenes travel.

centeroptional{ x, y }

An iris: where it closes on, in screen fractions, { x: 0, y: 0 } the top left corner. A cross iris: where it opens from.

blocksoptionalnumber

Pixelate: how many blocks across the short side of the screen at the worst of it, 2 or more.

maskoptionalstring

A dissolve and a cross dissolve, which need it: the picture whose greys say the order the screen is covered in, or the new scene shows through in. Found next to the motion file, or from the root of the game with a leading /; for a motion written in code, which has no file, from the page. It is fetched when the motion arrives, so it is usually there by the time it is needed, and the transition waits for it when it is not.

softnessoptionalnumber

A dissolve and a cross dissolve: how soft the edge of the shape is, from 0, hard, to 1.

Example

{ "type": "wipe", "duration": 0.4, "direction": "down" }
{ "type": "iris", "duration": 0.5, "center": { "x": 0.2, "y": 0.8 } }
{ "type": "dissolve", "duration": 0.8, "mask": "/assets/masks/star.png", "softness": 0.1 }
{ "type": "crossfade", "duration": 0.6 }
{ "type": "push", "duration": 0.5, "direction": "left" }
{ "type": "crossDissolve", "duration": 1.2, "mask": "../assets/masks/clock.png" }
View source · motion/types/t_motion_doc.ts:121

TSkeletalAnimationOptionstypenacatamalon

What to ask a model's bones to do.

Properties

playoptionalstring

Which movement to start on. Left out, it takes the first the file has.

loopoptionalboolean

Whether a movement goes round for ever. Default true. A repeat says how many times instead. One movement's own, in clips, comes first.

repeatoptionalnumber

How many extra times a movement runs after the first, as a tween's repeat: 2 is three times, then it ends, telling onEnd. Given, it decides, and with loop too it says so. One movement's own, in clips, comes first.

yoyooptionalboolean

Whether each time a movement runs again it comes back the other way, as a tween's yoyo: a breath, a sway, a door that swings to and fro, from a movement that only goes one way. Marks are passed on the way there, not on the way back. Default false. One movement's own, in clips, comes first.

speedoptionalnumber

How fast, as a multiple. Default 1.

fadeoptionalnumber

How long to take easing into a new movement, in seconds. Default 0, which is a cut.

onlyoptionaltypeOperator

Plays only on these bones, each with all that hangs from it, by the names the file gives them, over another animator of the same model: the legs run while the arms wave. The last one made goes on top. A bone its movement does not turn keeps showing the one below.

With only it starts on nothing rather than on the file's first movement, and when a movement ends or is stopped its bones go back to what is below, eased by fade. To keep a pose for as long as you need it, play a movement that goes round, or pause one, and stop when done.

clipsoptionalReadonly<Record<string, TSkeletalClipOptions>>

How each movement plays, by its name in the file: whether it goes round, how many times, what comes after it and the moments worth being told about. A movement not named here plays as the options above say. See TSkeletalClipOptions.

View source · hooks/animation/types/t_skeletal_animation.ts:69

TSkeletalCliptypenacatamalon

One named movement of a skeleton: walking, running, being hit.

Named apart from a sprite's TAnimationClip, which is a run of pictures. The two are the same idea in the two halves of the engine and share nothing at all.

It is plain data and holds nothing that is running. Two characters playing the same clip at different moments share this and keep their own time, which is what makes a crowd cheap.

Properties

type'clip'
namestring
durationnumber

How long it lasts, in seconds: the latest key any of its runs reaches.

channelsTSkeletalChannel[]
samplersTSkeletalSampler[]
View source · animation/types/t_animation_clip.ts:63

TSkeletalClipOptionstypenacatamalon

How one movement of a model plays: what its sprite twin, TAnimationClip, says on the clip, said here because a glTF file has nowhere to put it. The format says what moves and when, and nothing about whether it goes round or what any moment of it means. Somebody has to decide, once for each movement, and this is where.

Left out, a field is the animator's own (loop, repeat, yoyo of the options).

Properties

loopoptionalboolean

Whether it goes round for ever. A repeat says how many times instead.

repeatoptionalnumber

How many extra times it runs after the first: 2 is three times, then it ends, telling onEnd. Given, it decides, and with loop too it says so.

yoyooptionalboolean

Whether each time it runs again it comes back the other way.

eventsoptionaltypeOperator

Moments inside it worth being told about: the instant a blow lands, a foot meets the ground, a spell leaves the hand. at is in seconds from its start, because a movement off a file is a continuous thing with no pictures in it to count. Passed on the way there, not on the way back.

nextoptionalstring

The movement to play when this one ends, eased into by the animator's fade: an attack that goes back to standing. A name the file has no movement for is said once, and it rests where it ended.

View source · hooks/animation/types/t_skeletal_animation.ts:33

TSkeletontypenacatamalon

The bones of a model, and how they are standing right now.

It comes out of a file that was rigged: the bones themselves, which bone hangs from which, how they stand at rest, and what it takes to undo that rest position. Animation writes pose and nothing else; the graphics card reads jointMatrices and nothing else. That line down the middle is what keeps playing an animation, posing a skeleton and drawing it three separate problems.

Bones are a flat list, parents before their children, so working out where each one ended up is one pass from the front with nothing to recurse into.

Properties

type'skeleton'
keystring

What it is kept under: the model's name, plus which of its skeletons this is.

parentIndexInt32Array

The bone each one hangs from, -1 for one that hangs from nothing.

jointNamestypeOperator

What the file calls each bone, '' for one it does not name.

bindPoseTJointPose[]

How it stands when nothing is playing.

poseTJointPose[]

How it stands now. The only thing an animation of the whole body writes.

laid() => TJointPose[] | null

How it stands with what animators of part of the body lay over pose, or null for a skeleton with none, which is drawn as pose says.

inverseBindMatricesFloat32Array

What undoes the rest position, 16 numbers a bone.

jointMatricesFloat32Array

What the graphics card reads, 16 numbers a bone. Worked out from pose each frame.

rootMatricesFloat32Array | null

What sits above the bones that hang from nothing, 16 numbers a bone, or null when nothing does.

A rig is usually kept inside something: a file exported from Blender puts everything under one node that turns the whole scene upright. That turn is part of where a bone is, and the numbers undoing the rest position were written knowing it. Left out, the model is drawn a quarter turn away from where it belongs, and only on files that have such a node, which is why it is easy to ship without noticing.

posedOnnumber

Which frame jointMatrices was last worked out on, so the pieces of a model, which share its skeleton, do the work once between them. -1 before it has ever been done.

View source · animation/types/t_skeleton.ts:35

TSpriteAnimationtypenacatamalon

The controls for one animated sprite, returned by useSpriteAnimation.

Properties

play
pause
stop
setSpeed
playingboolean

Whether a run is going right now. False while it is paused or stopped, and once a clip that does not loop has finished.

clipstring | null

Which run is on, or null if none ever started.

framenumber

Which frame of the sheet is showing.

onEnd
onRepeat
onEvent
View source · hooks/animation/types/t_sprite_animation.ts:79

TSpriteAnimationOptionstypenacatamalon

What useSpriteAnimation is asked for.

Properties

clipsReadonly<Record<string, TAnimationClip>>

The runs this sprite knows, by name: walking, attacking, dying.

playoptionalstring

Which one to start with. Left out, the sprite stays on the frame it was created with.

speedoptionalnumber

A multiplier on every clip's speed: 2 twice as fast, 0.5 half. Default 1.

View source · hooks/animation/types/t_sprite_animation.ts:57

TTweenFieldstypenacatamalon

TTweenFields: conditional

The fields of an object a tween can move, as a path to each: { transform: { x: 200 }, tint: { a: 0 } }. Only the ends that are numbers can be named; everything on the way is optional.

View source · hooks/tween/types/t_tween.ts:74

TTweenHandletypenacatamalon

A tween, declared: the controls to play it, as many times as you like, and to hear how it goes. Nothing moves until play().

What a tween inside a tween.chain or a tween.all hears is still told (its onEnd when its step ends), but only the chain or the group is played, paused or stopped: those calls on what is inside it are an error.

Properties

play
pause
resume
stop
finish
reset
onEnd
onRepeat
onStop
playingboolean

Whether it is playing: from play until it ends or is stopped, waiting out its delay or paused included.

View source · hooks/tween/types/t_tween.ts:171

TTweenOptionstypenacatamalon

One trip of a number: where it starts, where it ends, how long it takes and what to do with the value along the way. Declared by useTween's function, and moved by its play().

A tween animates a number, not an object, and that is on purpose: onUpdate hands you the value and you decide where it goes. Into an x, into a width, into the amount of one colour mixed into another. Anything made of numbers can be animated without the tween knowing it exists.

When what moves is a field of an object (a sprite's x, its tint.a), TTweenTargetOptions says it shorter, with no onUpdate to write.

Properties

fromnumber

The value it starts at.

tonumber

The value it ends at.

durationnumber

How many seconds one trip takes.

easeoptionalTEaseFn

The shape of the movement: a function that takes how far along the trip is, from 0 to 1, and answers how far along the value should be. Default linear, which is the same speed all the way. easeOutBounce lands and bounces, easeOutElastic overshoots and wobbles back.

delayoptionalnumber

Seconds to wait before it starts moving. Default 0.

repeatoptionalnumber

How many extra times it runs after the first trip, so 1 means it goes twice. Default 0.

loopoptionalboolean

Whether it goes round for ever, until it is stopped or finished. repeat is for a number of times. Default false.

yoyooptionalboolean

Whether each repeat comes back the other way, there and back. Default false.

onUpdate(value: number) => void

Called every frame with the value right now. This is where you put it to use.

View source · hooks/tween/types/t_tween.ts:18

TTweenTargetOptionstypenacatamalon

One trip of the fields of an object: the object, where its fields end or how far they go, and how long they take.

target is the thing itself (the sprite) and to the path down to each number, not the object that holds the numbers. The path is followed again every frame, so a tint swapped for a new one halfway is the one that goes on fading.

  • to says where each field ends. Played again, it makes the same trip from the same start.
  • by says how far each field goes. Played again, it goes that far again from wherever the field is: a knockback, a jump, a step along.

Properties

targetT

What is moved: a sprite, a text, a box, any object with numbers in it.

tooptionalTTweenFields<T>

Where each field ends, by its path from target. It needs this, by, or both, for different fields.

byoptionalTTweenFields<T>

How far each field goes from where it starts, by its path from target.

fromoptionalTTweenFields<T>

Where each field starts. A field left out starts where it is the first time the tween moves, after its delay: in a tween.chain, where the step before left it. A field moved to keeps that start and goes back to it each time it is played again; one moved by starts from where it is every time.

durationnumber

How many seconds one trip takes.

easeoptionalTEaseFn

The shape of the movement, as in TTweenOptions. Default linear.

delayoptionalnumber

Seconds to wait before it starts moving. Default 0.

repeatoptionalnumber

How many extra times it runs after the first trip. Default 0.

loopoptionalboolean

Whether it goes round for ever, until it is stopped or finished. repeat is for a number of times. Default false.

yoyooptionalboolean

Whether each repeat comes back the other way, there and back. Default false.

Example

declare const hero: TSprite;

const tween = useTween();
tween({ target: hero, to: { transform: { x: 420 }, tint: { a: 0 } }, duration: 1 }).play();

// Each play pushes it 12 pixels further back, from wherever it is.
const knockback = tween({ target: hero, by: { transform: { x: -12 } }, duration: 0.2 });
View source · hooks/tween/types/t_tween.ts:111

nacatamalon/files

parseMotionDocfunctionnacatamalon/files

parseMotionDoc(raw: unknown, src: string) => TMotionDoc

Reads the contents of a .motion file, already parsed from JSON, into a motion.

It refuses what it could not play (another format, a track with no keys, a key with no time) with an error that names the file. The keys of each track come back in order of time, and a curve with a name the engine does not have is warned about and moved along in a straight line. Whether each track's box and field exist is not known here: that is answered when it plays in a scene.

Parameters

rawunknown

The file's JSON.

srcstring

Where it came from, for the errors.

View source · motion/parse_motion_doc.ts:271