# core/timemanager (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/core/timemanager/

Time manager.

## TimeManager extends Object

Time manager.

Example: Slow down time and read the frame interval

```js
import { Engine, EngineConfiguration, Scene } from "./build/vanilla.js";

class MainScene extends Scene {
	tick(timeDelta) {
		super.tick(timeDelta);
		const engine = this.getEngine();
		const timeManager = engine.getTimeManager();
		const unscaledTimeDelta = timeManager.getUnscaleDeltaTime();
		const time = timeManager.getTime();
		if (time >= 0.5 && time - unscaledTimeDelta < 0.5) {
			const framePerSecond = timeManager.getFramePerSecond();
			console.log(timeDelta, unscaledTimeDelta, framePerSecond);
		}
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());
const timeManager = engine.getTimeManager();
timeManager.setTimeScale(0.5);
timeManager.setMaximumTimeDelta(0.1);
```

- `constructor(engine)` (constructor, since 0.0.8): Constructor.
  - `engine` Engine: The engine that owns this manager. (not used)
- `update(timestamp)` (method, since 0.0.9): Time calculation.
  - `timestamp` number: Timestamp passed by requestAnimationFrame. (milliseconds)
- `getRealtimeSinceStartup()` (method, since 0.0.8): Returns the time since the current browser started. (in seconds)
  - returns number: Time since the page opened. (seconds, the time of the last update, 0 before the first update)
- `getTime()` (method, since 0.0.8): Returns the time since the current engine started. (in seconds)
  - returns number: Time accumulated since the engine started. (seconds, the sum of frame intervals clipped to the upper limit, without the time scale)
- `getUnscaleDeltaTime()` (method, since 0.0.9): Returns the elapsed time between the current frame and the previous frame. (in seconds)
  - returns number: Frame interval without the time scale. (seconds, 0 ~ upper limit)
- `getTimeDelta()` (method, since 0.0.8): Returns the elapsed time between the current frame and the previous frame. (in seconds)
  - returns number: Frame interval with the time scale applied. (seconds)
- `getFramePerSecond()` (method, since 0.0.8): Returns the current frames per second.
  - returns number: Number of frames counted during the last second. (0 during the first second)
- `setTimeScale(timeScale)` (method, since 0.0.9): Sets the time scale.
  - `timeScale` number: Time scale. (1 is normal, 0 makes getTimeDelta 0)
- `getTimeScale()` (method, since 0.0.9): Returns the time scale.
  - returns number: Time scale.
- `setMaximumTimeDelta(seconds)` (method, since 0.4.0): Sets the upper limit of one frame interval. (seconds, default 0.25)
  - The first frame interval after the window is hidden and comes back, or after a long pause, is clipped to this value. Less than 0 or not a number is set to 0.25.
  - Games where physics or flow must not advance a lot at once reduce it, like 0.1 or 0.05.
  - `seconds` number: Upper limit of one frame interval. (seconds)
- `getMaximumTimeDelta()` (method, since 0.4.0): Returns the upper limit of one frame interval. (seconds)
  - returns number: Upper limit of one frame interval. (seconds)
