Added paragraph about .getTime to GameLib introduction
@@ -35,6 +35,26 @@ GameLib enforces a clean division between server and client responsibilities:
|
||||
|
||||
Think of clients as "smart displays" that beautifully present the server's authoritative game state.
|
||||
|
||||
## Time Synchronization
|
||||
|
||||
A critical aspect of server-authoritative multiplayer is ensuring that all timing calculations are perfectly synchronized across devices. GameLib provides the [`.getTime()`](./ModuleClientAPI#gettime) function in the ModuleClientApi for this exact purpose:
|
||||
|
||||
```typescript
|
||||
// Get server-synchronized timestamp
|
||||
const syncedTime = api.getTime();
|
||||
```
|
||||
|
||||
The `.getTime()` function returns an epoch timestamp (in milliseconds) that is synchronized with the server. This must be used for all time-dependent calculations and game timing in your client code instead of local time functions like `Date.now()`.
|
||||
|
||||
Using `.getTime()` ensures that:
|
||||
|
||||
- All clients operate on the exact same time reference
|
||||
- Animations and transitions remain synchronized across devices
|
||||
- Time-based game mechanics (countdowns, intervals, etc.) are consistent for all players
|
||||
- Race conditions caused by client-side timing discrepancies are eliminated
|
||||
|
||||
**Important:** Always use `.getTime()` rather than native JavaScript timing functions when building time-sensitive game mechanics to maintain perfect synchronization in your multiplayer experience.
|
||||
|
||||
## Built-in Game Infrastructure
|
||||
|
||||
GameLib provides three essential infrastructure components that work seamlessly together through standardized APIs, giving you complete flexibility in how you implement your multiplayer experience.
|
||||
|
||||
Reference in New Issue
Block a user