githubEdit

Time API

Reference for time and deltaTime in Needle Engine

Access time data via this.context.time in components.


Properties

Property
Type
Description

time

number

Scaled time since app started (affected by timeScale)

deltaTime

number

Time since last frame (use for smooth animations)

frameCount

number

Total frames rendered since app started

realtimeSinceStartup

number

Unscaled time since app started (ignores timeScale)

timeScale

number

Time multiplier (default 1.0, set to 0.5 for slow-motion)


Frame-Rate Independent Movement

:::tip Always Use deltaTime Multiply movement by deltaTime for smooth, frame-rate independent animation:

this.gameObject.position.x += speed * this.context.time.deltaTime;

:::


Examples

Basic Movement


Rotation


Time-Based Logic


Slow Motion Effect


Frame Counting


Real Time (Unscaled)


Scaled vs Unscaled Time

Property
Affected by timeScale?
Use For

time

✅ Yes

Game logic, animations

deltaTime

✅ Yes

Movement, rotation

realtimeSinceStartup

❌ No

Profiling, UI timers, cooldowns that shouldn't pause


Common Patterns

Smooth Lerp

Clamp Movement Speed


Best Practices

✅ DO

  • Always use deltaTime for movement and animations

  • Use time for time-based triggers

  • Use realtimeSinceStartup for UI timers

  • Cache this.context.time if accessing multiple properties

❌ DON'T

  • Don't use fixed values for movement (not frame-rate independent)

  • Don't forget to multiply by deltaTime

  • Don't use Date.now() for game logic (use context.time)


Last updated