In NexusLang, time management is crucial for smooth gameplay and consistent behavior across different devices.
Every frame:
Move player based on input
Update animations
Check for collisions
Every physics frame:
Update physics simulation
Apply forces
Resolve collisions
When player takes damage:
Make player invincible
Wait for 2 seconds
Make player vulnerable again
Create countdown timer:
Start at 60 seconds
Every second:
Reduce time by 1
Update display
When reaches 0:
End game
Schedule "Spawn Enemy":
Every 5 seconds:
Create new enemy
If enemy count > 10:
Stop this schedule
Create time manager:
Set game speed to 1
When slow motion activated:
Set game speed to 0.5
Wait for 3 seconds
Return game speed to normal
When pause button pressed:
Pause game time
Show pause menu
Keep UI active
When resume selected:
Hide pause menu
Resume game time
Set target frame rate to 60
Enable vsync
If running on mobile:
Set target frame rate to 30
Create movement system:
Every frame:
Move objects based on:
Their speed
Multiplied by time since last frame
Create animation controller:
Play "walk" animation:
At 30 frames per second
Loop while moving
Play "jump" animation:
Once
At normal speed
Create particle effect:
Emit 10 particles per second
Each particle lives for 2 seconds
Fade out over last 0.5 seconds
# Good: Time-based updates
Every 0.5 seconds:
Update AI pathfinding
Check for distant enemies
# Avoid: Heavy operations every frame
Every frame:
Update only nearby objects
Skip complex calculations for distant objects
Create movement:
Set base speed to 5 units
Every frame:
Move based on:
Base speed
Times delta time
Times game speed
Create bullet time effect:
Slow game time to 0.2
Keep player at normal speed
Fade vision to blue
Wait for 5 seconds
Return all to normal