Sprites
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.visible:
Whether the sprite is visible.Example:
sprite.visible = false
sprite.size:
The size of the sprite.Example:
sprite.size = 50
sprite.transparency:
The transparency of the sprite (0-1).Example:
sprite.transparency = 0.5
sprite.tint:
The color tint of the sprite.Example:
sprite.tint = 0xFF0000
sprite.isTouching(other):
Checks if the sprite is touching another sprite.Example:
if (sprite.isTouching(otherSprite)) { ... }
Game
Core game functions and properties.
Game.getSprite(name):
Gets a sprite by name.Example:
const player = Game.getSprite('Player')
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
Control and Time
Functions for controlling timing and execution flow.
forever(callback):
Runs the function every frame.Example:
forever(() => { sprite.x += 1 })
every(seconds, callback):
Runs the function every specified number of seconds.Example:
every(2, () => { sprite.visible = !sprite.visible })
after(seconds, callback):
Runs the function after specified seconds.Example:
after(3, () => { sprite.size *= 2 })
wait(seconds):
Waits for specified seconds (use with async functions).Example:
async function move() { await wait(1); sprite.x += 10; }
Input
Functions for handling keyboard and mouse input.
Keyboard.keyDown(key):
Returns true if key was just pressed.Example:
if (Keyboard.keyDown(Key.Space)) { jump() }
Keyboard.keyUp(key):
Returns true if key was just released.Example:
if (Keyboard.keyUp(Key.Space)) { land() }
Keyboard.keyHeld(key):
Returns true if key is being held down.Example:
if (Keyboard.keyHeld(Key.ArrowRight)) { moveRight() }
Mouse.x, Mouse.y:
The mouse cursor position.Example:
sprite.x = Mouse.x; sprite.y = Mouse.y
Mouse.isDown(button):
Returns true if mouse button is pressed.Example:
if (Mouse.isDown(MouseButton.Left)) { shoot() }
Mouse.isOver(sprite):
Returns true if mouse is over sprite.Example:
if (Mouse.isOver(sprite)) { highlight() }
Cloning
Functions for working with sprite clones.
clone(sprite):
Creates a clone of a sprite.Example:
const newSprite = clone(sprite)
deleteClone(clone):
Deletes a cloned sprite.Example:
deleteClone(newSprite)
onCloneStart(callback):
Runs when a clone is created.Example:
onCloneStart((clone) => { clone.x = 0 })
Movement
Functions for sprite movement and positioning.
moveForward(sprite, distance):
Moves sprite forward.Example:
moveForward(sprite, 10)
move(amount):
Moves sprite by amount.Example:
move(5)
pointTowards(x, y):
Points sprite towards position.Example:
pointTowards(Mouse.x, Mouse.y)
distanceTo(x, y):
Gets distance to position.Example:
const dist = distanceTo(0, 0)
Math
Mathematical functions and constants.
Math.random(min, max):
Random number between min and max.Example:
const x = Math.random(0, 100)
Math.PI, Math.E:
Mathematical constants.Example:
sprite.rotation = Math.PI
Math.sin, Math.cos, Math.tan:
Trigonometric functions.Example:
sprite.y = Math.sin(time) * 100
Math.floor, Math.ceil, Math.round:
Rounding functions.Example:
const score = Math.floor(points)
Math.min, Math.max:
Value comparison.Example:
sprite.x = Math.min(sprite.x, 100)
Math.abs:
Absolute value.Example:
const distance = Math.abs(x2 - x1)
Math.clamp:
Constrains value between min and max.Example:
sprite.x = Math.clamp(sprite.x, 0, 100)
Events
Functions for handling events and messages.
on(sprite, event, callback):
Adds event listener to sprite.Example:
on(sprite, 'click', () => { sprite.visible = false })
sendMessage(name):
Sends a message to other sprites.Example:
sendMessage('gameOver')
onMessage(name, callback):
Listens for messages.Example:
onMessage('gameOver', () => { Game.stop() })