Motion
Get Motion

ReferenceScripting API

Scripting API

Everything a scene's script can use, in Motion 0.4: the types Studio checks your scripts against (motion.d.ts). Each type has its own page, named as TypeScript names it (MotionScene); the objects a script calls are the globals below (scene is a MotionScene). For a gentler start, read Logic as code.

Globals

NameTypeDescription
sceneMotionSceneThe scene: everything a script can do.
callable(options?: MotionCallableOptions) => Decorator & { pure: }Makes a method a node in the logic graph. callable.pure makes one without flow pins (the arrow-shaped ones), which only works out values. import { callable } from "motion"
classesMap<string, Function>Your scene's mote classes, by name. import { classes } from "motion"
mathsMotionMathsMaths for code: noise, easing, smooth steps, ranges (the same as scene.maths). import { maths } from "motion"
colourMotionColourColour for code (the same as scene.colour). import { colour } from "motion"
stageMotionStageApiThe scene's motes. import { stage } from "motion"

Layers

TypeKindDescription
MotionEffectinterfaceOne of a layer's effects (layer.effect).
MotionLayerinterfaceOne layer, to change without naming it each time (scene.layer).
MotionSceneinterfaceThe scene: everything a script can do.

Time

TypeKindDescription
MotionClockinterfaceThe clock where the desktop is.

Events

TypeKindDescription
MotionEventsinterfaceThe events scene.on hears, and what each hands its function.

Sound

TypeKindDescription
MotionAudiointerfaceWhat's playing, heard through the computer, 0 to 1 each.
MotionBeatinterfaceThe beat of what's playing.
MotionSoundinterfaceA sound of the script's own (scene.loadSound): played as many times as asked, each a voice.
MotionSoundLayerinterfaceA Sound layer, by its name or id (scene.sound).
MotionVoiceinterfaceOne playing of a sound: turned, panned, sped, moved, stopped, or crossed over to another sound. Read it with its properties, change it with its methods.

Video

TypeKindDescription
MotionVideointerfaceA Video layer's film (scene.video).
VideoComponentclassA Video layer of a mote.

Particles

TypeKindDescription
MotionParticlesinterfaceA particle layer's system (scene.particles): bursts, rates, pausing and clearing.
ParticleComponentclassA particle layer of a mote.

3D

TypeKindDescription
CameraComponentclassA 3D layer's camera, as a mote's component (its layer the 3D layer).
MeshComponentclassOne item of a 3D layer: its settings are the item's own; a model's clips play here.
MotionCamerainterfaceA 3D layer's camera (scene.camera).

Timeline

TypeKindDescription
MotionTimelineinterfaceThe clock the scene's keyframes go by (scene.timeline): the scene's own time until a script plays, holds, seeks or speeds it.

Pointer

TypeKindDescription
DragComponentclassLets the pointer drag its mote: pressed on it, the mote follows the pointer until let go.
MotionPointerinterfaceThe pointer over the wallpaper.

World

TypeKindDescription
MotionMediainterfaceWhat's playing on the desktop (scene.media), as its media session says.
MotionSysteminterfaceThe computer's load (scene.system).
MotionWeatherinterfaceThe weather where the desktop is (scene.weather), as a Weather layer shows it.

Web

TypeKindDescription
MotionFetchedinterfaceWhat scene.fetch gives back.

Numbers and colours

TypeKindDescription
MotionColourinterfaceColour for code (scene.colour, or import { colour } from "motion"): colours are "#rrggbb".
MotionMathsinterfaceMaths for code, as the logic graph's nodes have it (scene.maths, or import { maths } from "motion").

Memory

TypeKindDescription
MotionStoreinterfaceWhat a script keeps between runs (256 KB as JSON, 64 keys).

Motes

TypeKindDescription
ComponentclassA part of a mote, bound to one of its layers (or a 3D layer's item).
MoteclassA thing in the scene with a place, made of components bound to its layers.
MotionStageApiinterfaceThe scene's motes: found, spawned and destroyed, and their physics.
SignalclassAn event others can bind to: sent by one, heard by any number.
StageclassThe scene's own: one is made, to hear the scene; it has all of the stage's.
Vector2classA point or direction in 2D.
Vector3classA point or direction in 3D (a 2D mote's z is its depth).

Physics

TypeKindDescription
BodyComponentclassA mote's body, which Motion's physics moves.
JointComponentclassJoins its mote's body to another's (stage.join), from connect() until disconnect().

The Stage

TypeKindDescription
AudioComponentclassNot in Motion yet: one does nothing for now.
CharacterComponentclassNot in Motion yet: one does nothing for now.
ColliderComponentclassNot in Motion yet: one does nothing for now (a body's collider is the body's own shape).
DriveComponentclassNot in Motion yet: one does nothing for now.
EffectComponentclassAn effect layer of a mote.
FollowComponentclassNot in Motion yet: one does nothing for now.
ImageComponentclassAn Image layer of a mote.
LayerComponentclassA layer of a mote.
LightComponentclassA light of a 3D layer.
MotionHitinterfaceWhere a mote was clicked: in the scene's pixels (location) and 0 to 1 (x, y), and with which button.
MotionJointSpecinterfaceHow two motes' bodies are joined (stage.join).
MotionRayHitinterfaceWhat a ray met.
MotionTickinginterfaceHow often a mote ticks.
MovementComponentclassNot in Motion yet: one does nothing for now.
NestedSceneComponentclassA scene layer of a mote.
PathComponentclassNot in Motion yet: one does nothing for now.
RotatingComponentclassNot in Motion yet: one does nothing for now.
RotatorinterfacePitch, yaw and roll, in degrees.
ShaderComponentclassA Shader layer of a mote.
ShapeComponentclassA Shape layer of a mote.
SpriteComponentclassA Sprite layer of a mote.
TextComponentclassA Text layer of a mote.
TimelineComponentclassNot in Motion yet: one does nothing for now.
TransformComponentclassA mote's place (its own).
WanderComponentclassNot in Motion yet: one does nothing for now.
WebComponentclassA web layer of a mote.

Types

TypeKindDescription
EasingtypeHow a move eases: one of the names, a cubic Bézier's control points [x1, y1, x2, y2] (as CSS has them), or a curve drawn as values evenly along it ({ curve: [y0, y1, ...] }).
MotionAnimateOptionsinterfaceHow scene.animate moves: its easing ("easeInOut" unless given), a delay before it starts (seconds), and whether it loops (true round and round, "pingpong" there and back).
MotionBoundsinterfaceWhere a layer is on the scene, 0 to 1 of it: the box round it, and its turn in degrees.
MotionCallableOptionsinterfaceWhat the callable decorator takes: the node's title, where the palette shows it, and how it's drawn.
MotionEventinterfaceOne of the calendar's events: its title, start and end (ms since 1970, local time), and whether it lasts all day.
MotionEventOptionsinterfaceWhat scene.on's handler for loud or quiet listens for.
MotionLayerInfointerfaceA layer as scene.layers lists it.
MotionPlaceinterfaceA place for the weather, as a Weather layer's place names it: where it is, to a tenth of a degree, and its name.
MotionPlaceableOptionsinterfaceWhat the placeable and component decorators take: where Studio's palette shows the class, and the words it finds it by.
MotionPlayOptionsinterfaceHow a sound plays: its volume (0 to 2), pan (-1 left to 1 right), speed (0.25 to 4, faster is higher), whether it loops, its fade in and where it starts (seconds).
MotionPropertyOptionsinterfaceWhat the property decorator takes: its range, unit and label in Studio's Details, and whether it's shown, exposed and kept.
SettingValuetypeA layer's setting's value: a number, words, true or false, a colour ("#rrggbb") or a list.

The labels for plain numbers and words that give a node's input its unit or a slider in Studio (Seconds, Metres, Int, Ranged<0, 1>…) are on Units and values.

Older scripts may use the names these types had before, which still work: AnimateOptions is MotionAnimateOptions, CallableOptions is MotionCallableOptions, Hit is MotionHit, JointSpec is MotionJointSpec, PlaceableOptions is MotionPlaceableOptions, PropertyOptions is MotionPropertyOptions, RayHit is MotionRayHit, StageApi is MotionStageApi, Ticking is MotionTicking.

The "motion" module

TypeKindDescription
motionmoduleWhat a script imports from "motion": the Stage's helpers, the decorators that make a class's members show in Studio, and the shared objects.