https://github.com/mtojo/node-game
Game loop library for Node.js
https://github.com/mtojo/node-game
game-loop nodejs
Last synced: 11 months ago
JSON representation
Game loop library for Node.js
- Host: GitHub
- URL: https://github.com/mtojo/node-game
- Owner: mtojo
- Created: 2012-12-30T02:16:46.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2021-05-13T19:12:26.000Z (about 5 years ago)
- Last Synced: 2023-03-22T10:57:00.626Z (over 3 years ago)
- Topics: game-loop, nodejs
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-game
Game loop library for Node.js.
## Installation
```bash
$ npm install --save https://github.com/mtojo/node-game.git
```
## Usage
```js
const Game = require('game');
const game = new Game({
framesPerSecond: 60,
maxFrameSkip: 10,
waitTime: 0
});
game.on('init', () => {
// This function is called when the Game object is initialized.
});
game.on('start', () => {
// This function is called when the game loop is started.
});
game.on('update', () => {
// This function is called every frame.
});
game.on('stop', () => {
// This function is called when the game loop is stopped.
});
game.start();
```
## API
### Game
#### constructor(options = {})
##### options
| Name | Description | Default |
| ---- | ----------- | ------- |
| `framesPerSecond` | Frames per second. | `60` |
| `maxFrameSkip` | Max number for frame skip. | `10` |
| `waitTime` | Milliseconds for loop wait. | `0` |
#### get isRunning
type: `boolean`
Returns whether the game loop is running.
#### get updateTicks
type: `number`
Returns the number of the updated.
#### get currentTick
type: `number`
Returns the number of the updated on current second.
#### set framesPerSecond
type: `number`
Sets the frames per second.
#### get framesPerSecond
type: `number`
Returns the frames per second.
#### set maxFrameSkip
type: `number`
Sets the max number for frame skip.
#### get maxFrameSkip
type: `number`
Returns the max number for frame skip.
#### set waitTime
type: `number`
Sets the milliseconds for loop wait.
#### get waitTime
type: `number`
Returns the milliseconds for loop wait.
#### start()
Starts the game loop.
#### stop()
Stops the game loop.
## License
MIT