Time
Read frame timing and pause state from gameplay scripts. Use Time when you
need movement, cooldowns, animations, timers, or physics-related code to behave
consistently across different frame rates.
Namespace:
namespace Lenga\Engine\Core;
class Time
Methods
time
public static function time()
Returns the total game time in seconds since the current run started.
unscaledTime
public static function unscaledTime()
Returns the real time elapsed since application start, unaffected by pause.
deltaTime
public static function deltaTime()
Returns the time elapsed since the last frame.
unscaledDeltaTime
public static function unscaledDeltaTime()
Returns the real frame delta time, unaffected by pause.
fixedDeltaTime
public static function fixedDeltaTime()
Returns the fixed delta time value.
fixedStepCount
public static function fixedStepCount()
isPaused
public static function isPaused()
Example
use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\Time;
class MovementController extends Behaviour
{
public float $speed = 5.0;
public function update(): void
{
// Frame-rate-independent movement
$moveDistance = $this->speed * Time::deltaTime();
$this->transform->translate($moveDistance, 0, 0);
// Get time since game started
$elapsedTime = Time::time();
Debug::log('Time elapsed: ' . $elapsedTime);
}
public function fixedUpdate(): void
{
// Physics updates use fixed delta time
$fixedDelta = Time::fixedDeltaTime();
// Apply physics calculations with consistent timestep
}
}