# misc/loadingprogress (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/misc/loadingprogress/

Loading progress.

## LoadingProgress extends Object

Loading progress.
- The shown progress (getShownProgress) smoothly follows the progress reported by the loading stages (setProgress, 0 ~ 1, never decreases).
  Even if progress jumps at once because loads bunch up, the bar slides instead of jumping.
- Call update(timeDelta) every frame. The follow fraction is 1 - exp(-speed * time), so the speed is the same even with different frame intervals.

Example: Let the shown progress follow the reported progress

```js
import { LoadingProgress } from "./build/vanilla.js";

const loadingProgress = new LoadingProgress(6);
loadingProgress.setProgress(0.5);
for (let frame = 0; frame < 30; ++frame) {
	loadingProgress.update(1 / 60);
}
console.log(loadingProgress.getProgress(), loadingProgress.getShownProgress().toFixed(3));

loadingProgress.setProgress(0.3);
console.log(loadingProgress.getProgress());

loadingProgress.setProgress(1);
while (!loadingProgress.isFinished()) {
	loadingProgress.update(1 / 60);
}
console.log(loadingProgress.getShownProgress());
```

- `constructor(followRate = DEFAULT_FOLLOW_RATE)` (constructor, since 0.4.0): Constructor.
  - `followRate` number: Follow speed. (Fraction of the remaining distance per second, default 6)
- `setProgress(progress)` (method, since 0.4.0): Sets the reported progress. (Clamped to 0 ~ 1, ignored if smaller than what was reported before)
  - `progress` number: Progress to report. (0 ~ 1)
- `getProgress()` (method, since 0.4.0): Returns the reported progress.
  - returns number: 0 ~ 1
- `getShownProgress()` (method, since 0.4.0): Returns the shown progress. (Read when drawing)
  - returns number: 0 ~ 1
- `update(timeDelta)` (method, since 0.4.0): Updates. (The shown progress follows the reported progress)
  - `timeDelta` number: Time since the last frame. (Seconds)
- `setFollowRate(followRate)` (method, since 0.4.0): Sets the follow speed. (Fraction of the remaining distance per second, must be greater than 0. Otherwise left unchanged)
  - `followRate` number: Follow speed. (Fraction of the remaining distance per second)
- `getFollowRate()` (method, since 0.4.0): Returns the follow speed.
  - returns number: Follow speed. (Fraction of the remaining distance per second)
- `isFinished()` (method, since 0.4.0): Whether the shown progress has reached the end (1).
  - returns boolean: True if the shown progress has reached 1.
- `reset()` (method, since 0.4.0): Resets. (Sets the reported progress and the shown progress to 0)
