Helper Classes
Utility classes for common tasks.
Writing game logic just got cleaner. No more drilling through this.entity.scene.game... chains every single time.
Shorthand API
Access common properties and methods directly from your script components.
js
// Before → After
this.entity.destroy() → this.destroy()
this.entity.hasTag("wall") → this.hasTag("wall")
this.entity.scene.findByTag("wall") → this.findByTag("wall")
this.entity.scene.findAllByTag("wall") → this.findAllByTag("wall")
this.entity.scene.raycast(Mouse.x, Mouse.y) → this.raycast(Mouse.x, Mouse.y)
this.entity.scene.pick(Mouse.x, Mouse.y) → this.pick(Mouse.x, Mouse.y)
this.entity.scene → this.scene
this.entity.scene.game → this.game
this.entity.scene.game.camera → this.cameraKeyCode & MouseButton
No more magic strings or raw numbers buried in your input checks:
js
if (Keyboard.isPressed(KeyCode.W)) // was: "w"
if (Keyboard.wasPressed(KeyCode.Space)) // was: "Space"
if (Mouse.wasPressed(MouseButton.Left)) // was: 0
if (Mouse.wasPressed(MouseButton.Right)) // was: 2
if (Mouse.wasPressed(MouseButton.Middle)) // was: 1Vector2 / Vector3
js
const a = new Vector2(10, 5);
const b = new Vector2(3, 2);
Vector2.add(a, b) // → Vector2(13, 7)
Vector2.sub(a, b) // → Vector2(7, 3)
Vector2.distance(a, b) // → number
Vector2.lerp(a, b, 0.5) // → smooth midpoint
Vector2.dot(a, b) // → scalar
a.normalize() // modifies in place, returns self
a.clone() // safe copyMathf
js
Mathf.clamp(health, 0, 100) // never go below 0 or above 100
Mathf.lerp(currentVal, target, 0.1) // smooth follow / easing
Mathf.degToRad(90) // → 1.5707...
Mathf.radToDeg(Math.PI) // → 180Timer & Cooldown
js
// Timer — great for wave spawning, cutscenes, and delayed events
const waveTimer = new Timer(5.0, true); // 5 seconds, starts immediately
update(dt) {
waveTimer.update(dt);
if (waveTimer.isFinished()) {
spawnNextWave();
waveTimer.start(); // loop it
}
}
// Cooldown — fire rates, dash recharge, ability delays
const fireCooldown = new Cooldown(0.2); // 5 shots per second
update(dt) {
fireCooldown.update(dt);
if (Mouse.wasPressed(MouseButton.Left) && fireCooldown.trigger()) {
this.instantiate(Bullet, x, y);
}
}Utility Functions
js
Random.range(1, 10); // random float between 1 and 10
Random.int(1, 10); // random int between 1 and 10
HexToRGB("#ff0000") // → { r: 255, g: 0, b: 0 }
RGBToHex(255, 0, 0) // → "#ff0000"Raycasting (with options)
js
const hit = this.raycast(Mouse.x, Mouse.y, {
layerMask: Layers.Enemy,
tag: "boss",
ignore: this.entity
});
if (hit) {
console.log("Hit:", hit.entity.name);
}Tags, Layers & Raycasting
js
entity.tag = "enemy";
entity.layer = Layers.Enemy;
// Scene queries
const boss = this.findByTag("boss");
const allEnemies = this.findAllByTag("enemy");
// Raycast — only hits enemies, ignores everything else
const hit = this.raycast(Mouse.x, Mouse.y, { layerMask: Layers.Enemy, ignore: this.entity });
if (hit) console.log("Hit:", hit.entity.name);