Skip to content

Motion functions

Free functions you can call directly in sprite code.

changeDirection(amount: number): void

Change this sprite’s direction by an amount.

Delegates to Sprite.direction

changeX(amount: number): void

Change this sprite’s x position by an amount.

Delegates to Sprite.x

Used by

changeY(amount: number): void

Change this sprite’s y position by an amount.

Delegates to Sprite.y

Used by

getDirection(): number

Get this sprite’s current direction in degrees.

Delegates to Sprite.direction

getX(): number

Get this sprite’s x position.

Delegates to Sprite.x

getY(): number

Get this sprite’s y position.

Delegates to Sprite.y

glide(seconds: number, x: number, y: number): void

Glide this sprite to a position over a number of seconds.

Pauses the script (a generator). In sprite code the free-function wrapper awaits it for you.

Delegates to Sprite.glide

Used by

goto(x: number, y: number): void

Move this sprite to the given x and y coordinates.

Delegates to Sprite.goto

ifOnEdgeBounce(): void

Bounce off the edge of the stage if touching it.

Delegates to Sprite.ifOnEdgeBounce

Used by

move(steps: number): void

Move this sprite forward by a number of steps.

Delegates to Sprite.move

Used by

pointTowards(target: "mouse" | { x: number; y: number }): void

Point this sprite towards another sprite or the mouse (“mouse”).

Delegates to Sprite.direction

positionInFence(): void

Clamp this sprite’s position to stay within the stage fence.

Delegates to Sprite.positionInFence

setDirection(direction: number): void

Point this sprite in the given direction (degrees).

Delegates to Sprite.direction

Used by

setRotationStyle(style: symbol): void

Set how this sprite rotates when its direction changes.

Delegates to Sprite.rotationStyle

setX(x: number): void

Set this sprite’s x position.

Delegates to Sprite.x

setY(y: number): void

Set this sprite’s y position.

Delegates to Sprite.y

turnClockwise(degrees: number): void

Turn this sprite clockwise by a number of degrees.

Delegates to Sprite.direction

turnCounterClockwise(degrees: number): void

Turn this sprite counter-clockwise by a number of degrees.

Delegates to Sprite.direction