# accurate-game-loop

> A very accurate game loop, down to the nanosecond

Latest version **2.0.0** (published 2021-05-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install accurate-game-loop
pnpm add accurate-game-loop
yarn add accurate-game-loop
bun add accurate-game-loop
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-05-03 |
| First published | 2021-04-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | ZeroTix |
| Maintainers | zerotix |
| Keywords | loop, gameloop, nodejs game loop, accurate game loop, fast game loop |

## Links

- npm: https://www.npmjs.com/package/accurate-game-loop
- Repository: https://github.com/ZeroTixDev/accurate-game-loop
- Homepage: https://github.com/ZeroTixDev/accurate-game-loop#readme
- Issues: https://github.com/ZeroTixDev/accurate-game-loop/issues
- npm.io page: https://npm.io/package/accurate-game-loop

## Recent versions

- 2.0.0 (latest) — 2021-05-03
- 1.1.0 — 2021-05-03
- 1.0.3 — 2021-04-27
- 1.0.2 — 2021-04-27
- 1.0.1 — 2021-04-27
- 1.0.0 — 2021-04-26

## README

# Accurate Game Loop
A library for nodejs game loops (not meant for browser), this package is pretty much the most accurate you can get with nodejs
# Install
```bash
npm install accurate-game-loop
```
# Usage / Documentation
```ts
const Loop = require('accurate-game-loop');
```
## Creating a loop
```ts
const timesPerSecond = 60;
const update = () => {
    // do something smart
};
const loop = new Loop(update, timesPerSecond);
```
## Starting a loop
```ts
loop.start();
// or
const loop = new Loop(...params).start();
```
## Stopping a loop
```ts
loop.stop();
```
# Options:
```ts
new Loop(
    update,
    timesPerSecond,
    {...options}
)
```
## Logs
#### This automatically enables every type of log internally (Useful for debug)
### Implementation:
```ts
new Loop(
    update,
    timesPerSecond,
    { logs: true }
)
```
### Example:
![Screenshot](https://cdn.discordapp.com/attachments/834833750948970506/838566696834301952/unknown.png)
## Delta Log
#### This automatically logs the time differences between the update calls
### Implementation:
```ts
new Loop(
    update,
    timesPerSecond,
    { delta_log: true }
)
```
### Example:
![Screenshot](https://media.discordapp.net/attachments/834833750948970506/838561596791848960/unknown.png)
## Difference Log
#### This automatically logs the time shifts that the code makes internally
### Implementation:
```ts
new Loop(
    update,
    timesPerSecond,
    { dif_log: true }
)
```
### Example:
![Screenshot](https://cdn.discordapp.com/attachments/834833750948970506/838566069941567488/unknown.png)
## Time Function
#### This allows you to specify the time function you want (expects it to return in nanoseconds)
### Example / Implementation:
```ts
new Loop(
    update,
    timesPerSecond,
    { time_fn: () => Date.now() * 1e6 }
)
```
### If you have any questions, you can make a github issue or dm me on discord at ZeroTix#6300   (I respond quick)

---
_Source: https://npm.io/package/accurate-game-loop · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
