Timer)
The engine includes a high-precision timer system based on real game time (dt),
allowing you to execute functions automatically after a specified number of seconds,
with the option to repeat indefinitely.
It is ideal for scheduling events, animations, explosions, shots, spawns, or any time-based logic.
setTimeout() or setInterval(),
the Timer system is fully integrated into the engine and synchronized with the game loop.
It works the same in the editor, Play mode, or Web/PWA builds.
Timer(seconds, functionName, loop, target)
Creates a new timer that will execute a function after a given number of seconds.
It can repeat automatically if the loop parameter is enabled.
Timer(seconds, functionName, loop = false, target = null);
0.1).CallFunction().true, the timer repeats indefinitely.Start(obj) or Update(obj)).Does not return a value. The timer is handled automatically.
// Script: bomb.js
function Start(obj) {
console.log("💣 Bomb activated...");
Timer(3, "Explode", false, obj); // Calls Explode(obj) after 3 seconds
}
function Explode(obj) {
console.log("💥 BOOM!", obj.name);
destroyObject(obj);
}
// Generate enemies every 2 seconds
function Start(obj) {
Timer(2, "SpawnEnemy", true, obj);
}
function SpawnEnemy(obj) {
console.log("👾 New enemy spawned by:", obj.name);
}
CallFunction(target, functionName).target parameter must be a valid engine object.clearTimer(functionName)Cancels a specific timer or all active timers.
clearTimer(functionName = null);
// Cancel a specific timer
clearTimer("SpawnEnemy");
// Cancel all active timers
clearTimer();
pauseTimers(pause)Pauses or resumes all active timers simultaneously.
pauseTimers(pause = true);
true to pause, false to resume.// Pause the game and all timers
pauseTimers(true);
// Resume the game and timers
pauseTimers(false);
// Script: turret.js
function Start(obj) {
console.log("🔫 Turret activated");
Timer(1, "Shoot", true, obj); // shoots every second
}
function Shoot(obj) {
console.log("💥 Shot from", obj.name);
spawnBullet(obj);
}
function spawnBullet(obj) {
const bullet = instantiatePrefab("Bullet");
bullet.x = obj.x + obj.w / 2;
bullet.y = obj.y;
}
update(dt)).