Motion
Properties and methods for working with sprites.
sprite.x:
The horizontal position of the sprite.Example:
sprite.x = 100
sprite.y:
The vertical position of the sprite.Example:
sprite.y = 200
sprite.rotation:
The rotation of the sprite in degrees.Example:
sprite.rotation = 45
sprite.pointTowards(x, y):
Points sprite towards a specific position.Example:
sprite.pointTowards(100, 200)
Looks
Properties for sprite appearance.
sprite.visible:
Whether the sprite is visible.Example:
sprite.visible = false
sprite.size:
The size of the sprite.Example:
sprite.size = 50
sprite.layer:
The layer of the sprite.Example:
sprite.layer = 1
sprite.transparency:
The transparency of the sprite (0-100).Example:
sprite.transparency = 50
sprite.brightness:
The brightness of the sprite (0-100).Example:
sprite.brightness = 50
Control
Functions for controlling timing and execution flow.
forever(function):
Runs the function every frame.Example:
forever(function() { sprite.x += 1 })
for(let i = 0; i < n; i++) { ... }:
Runs the code in the curly braces n times.Example:
for(let i = 0; i < 10; i++) { sprite.x += 1 }
while (condition) { ... }
Runs the code in the curly braces repeatedly while the condition is true.Example:
while (sprite.x < 100) { sprite.x += 1 }
if (condition) { ... }
Executes the block if the condition is true.Example:
if (sprite.x > 100) { sprite.visible = false }
if (condition) { ... } else { ... }
Executes one block if the condition is true, otherwise runs the else block.Example:
if (sprite.x > 100) { sprite.visible = false } else { sprite.visible = true }
sendMessage("messageName")
Sends a message to all spritesExample:
sendMessage("gameOver")
onMessage("messageName", function() { ... })
Receives a message and runs the code in the curly braces when the message is received.Example:
onMessage("gameOver", function() { Game.stop() })
wait(seconds):
Waits for specified seconds (use with async functions).Example:
async function move() { await wait(1); sprite.x += 10; }
Sensing
Functions for handling detection and keyboard and mouse input.
sprite.isTouching("spriteName"):
Checks if the sprite is touching the other sprite with the given name.Example:
if (sprite.isTouching("Enemy")) { ... }
sprite.touchingMouse():
Checks if the sprite is touching the mouse cursor.Example:
if (sprite.touchingMouse()) { ... }
Keyboard.keyDown(key):
Returns true if key was just pressed.Example:
if (Keyboard.keyDown(Key.Space)) { sprite.y += 10 }
Keyboard.keyHeld(key):
Returns true if key is being held down.Example:
if (Keyboard.keyHeld(Key.ArrowRight)) { sprite.x += 1 }
Keyboard.keyUp(key):
Returns true if key was just released.Example:
if (Keyboard.keyUp(Key.Space)) { sprite.y -= 10 }
Mouse.isDown(button):
Returns true if mouse button is pressed.Example:
if (Mouse.isDown(MouseButton.Left)) { sprite.size += 10 }
Mouse.isHeld(button):
Returns true if mouse button is held down.Example:
if (Mouse.isHeld(MouseButton.Left)) { sprite.size += 1 }
Mouse.isUp(button):
Returns true if mouse button is released.Example:
if (Mouse.isUp(MouseButton.Left)) { sprite.size -= 1 }
Mouse.x:
The current horizontal position of the mouse cursor.Example:
sprite.x = Mouse.x
Mouse.y:
The current vertical position of the mouse cursor.Example:
sprite.y = Mouse.y
Math
Mathematical functions, comparisons, and constants.
Math.random(min, max):
Returns a random number between min and max.Example:
let n = Math.random(0, 10)
Math.round(value):
Rounds the value to the nearest whole number.Example:
Math.round(0.5)
Math.floor(value):
Rounds the value down to the nearest whole number.Example:
Math.floor(0.5)
Math.ceil(value):
Rounds the value up to the nearest whole number.Example:
Math.ceil(0.5)
Math.abs(value):
Returns the absolute (positive) value.Example:
let distance = Math.abs(x - y)
<
Returns true if the left value is less than the right value.Example:
if (x < 10) { ... }
>
Returns true if the left value is greater than the right value.Example:
if (score > 100) { ... }
<=
Returns true if the left value is less than or equal to the right value.Example:
if (lives <= 0) { Game.stop() }
>=
Returns true if the left value is greater than or equal to the right value.Example:
if (score >= 100) { ... }
==
Checks if two values are equal.Example:
if (level == 2) { ... }
!=
Checks if two values are not equal.Example:
if (sprite.x != 0) { ... }
Math.sin(angle):
Returns the sine of the angle (in degrees).Example:
let y = Math.sin(90)
Math.cos(angle):
Returns the cosine of the angle (in degrees).Example:
let x = Math.cos(0)
Math.tan(angle):
Returns the tangent of the angle (in degrees).Example:
let slope = Math.tan(45)
Math.PI:
Represents the mathematical constant π (~3.14159).Example:
let radius = 2 * Math.PI * r
Math.E:
Represents Euler’s number (~2.718).Example:
let growth = Math.E ** time
Clones
Functions for working with sprite clones.
onCloneStart(function(clone){ ... }):
Runs when a clone is created.Example:
onCloneStart((clone) => { clone.x = 0 })
createClone():
Creates a clone of the current sprite, or the sprite with the given name if provided.Example:
let newSprite = createClone()
deleteClone():
Deletes the current clone in the onCloneStart.Example:
deleteClone()
Game
Core game functions and properties.
Game.stop():
Stops the game.Example:
Game.stop()
Game.width:
The width of the game window.Example:
sprite.x = Game.width / 2
Game.height:
The height of the game window.Example:
sprite.y = Game.height / 2
Arrays
Create, modify, and access array data.
let array: type[] = []:
Creates a new empty array. Types include: number, string, boolean, etc.Example:
let scores: number[] = []
array.push(value):
Adds a value to the end of the array.Example:
scores.push(10)
array.splice(index, 1):
Removes the item at the given index.Example:
scores.splice(2, 1)
array.splice(index, 0, item):
Inserts an item at the specified index.Example:
scores.splice(1, 0, 99)
array[index] = item:
Replaces the item at the specified index.Example:
scores[0] = 42
array[index]:
Gets the item at the given index.Example:
let value = scores[1]
array.length:
Gets the number of items in the array.Example:
let count = scores.length
array[0]:
Gets the first item in the array.Example:
let first = scores[0]
array[array.length - 1]:
Gets the last item in the array.Example:
let last = scores[scores.length - 1]
array.sort():
Sorts the array alphabetically or numerically.Example:
scores.sort()
array.reverse():
Reverses the order of the array.Example:
scores.reverse()
array.map(item => ...):
Creates a new array by transforming each item.Example:
let doubled = scores.map(x => x * 2)
array.filter(item => ...):
Creates a new array with only the items that pass the condition.Example:
let highScores = scores.filter(x => x > 50)