Viewing: Scripting
Scripting (Phaser-powered)
Tulio scripts are plain JavaScript modules that run at play-time.
Tulio does not attempt to hide Phaser. In practice, you’ll often use Phaser APIs when writing gameplay code.
The mental model
- You write a class that extends
TulioBehaviour. - Tulio attaches your behaviour(s) to a runtime game object. You can attach multiple scripts to the same object.
- Your behaviour can use:
ctx.scene(a PhaserScene)this.gameObject(a Phaser Game Object)this.transform(a Tulio convenience wrapper around transform)
Behaviour lifecycle
If present, Tulio calls:
create(ctx, props)— once when the object is created/spawnedupdate(dt, ctx, props)— every frame
Where:
dtis delta time in secondspropsare inspector properties resolved for the scriptctxcontains runtime helpers (and always includesctx.scene)
Example
export default class PlayerController extends TulioBehaviour {
static properties = {
speed: { type: 'number', default: 200 }
};
create(ctx, props) {
this.keys = ctx.scene.input.keyboard.addKeys({
left: 'A',
right: 'D'
});
}
update(dt, ctx, props) {
const speed = Number(props.speed) || 0;
if (this.keys.left.isDown) this.x -= speed * dt;
if (this.keys.right.isDown) this.x += speed * dt;
}
}
Helper functions
Tulio exposes a small set of GameMaker-style math helpers.
point_distance/pointDistancepoint_direction/pointDirectionlengthdir_x/lengthdirXlengthdir_y/lengthdirYdegToRad,radToDeg,clamp,lerp
When to use Phaser docs
You’ll most likely reach for Phaser documentation when you:
- Use physics and collisions
- Use cameras, containers, animations, particles
- Do advanced input handling
- Optimize performance