Skip to content

Commit

Permalink
improve/fix README
Browse files Browse the repository at this point in the history
- fix import paths
- include CDN installation instructions
- clean up basic example code
  • Loading branch information
brianchirls committed Aug 1, 2022
1 parent 3f15e14 commit c3e8f6e
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,46 @@ Built-in support for the following device types:

## Installation

### npm

Install via [npm](https://npmjs.com).

```sh
$ npm install @brianchirls/game-input
npm install @brianchirls/game-input
```

And import each class individually

```javascript
import Gamepad from '@brianchirls/game-input/devices/Gamepad';
import Action from '@brianchirls/game-input/Action';

```

### CDN

Or load directly from CDN
```html
<script src="https://unpkg.com/@brianchirls/game-input"></script>
```

And access classes on the global `GameInput` object.

```javascript
const myGamepad = new GameInput.Gamepad();
```

## Basic Example

```typescript
import Gamepad from '@brianchirls/game-input/devices/Gamepad';
import Keyboard from '@brianchirls/game-input/devices/Keyboard';
import DPadComposite from '@brianchirls/game-input/controls/DPadComposite';
import Action from '@brianchirls/game-input/Action';

/**
* devices
*/
import Gamepad from '../src/devices/Gamepad';
import Keyboard from '../src/devices/Keyboard';

const gamepad = new Gamepad();
const keyboard = new Keyboard();
Expand All @@ -45,7 +70,6 @@ const keyboard = new Keyboard();
const leftStick = gamepad.getControl('leftStick');

// It takes four keys to go in four directions
import DPadComposite from '../src/controls/DPadComposite';
const kbdWASD = new DPadComposite({
up: kbd.getControl('KeyW'),
left: kbd.getControl('KeyA'),
Expand All @@ -58,7 +82,6 @@ const kbdWASD = new DPadComposite({
* The action will respond to whichever control is used.
*/

import Action from '../src/Action';
const moveAction = new Action({
bindings: [
leftStick,
Expand All @@ -76,7 +99,7 @@ function update() {

const [x, y] = moveAction.value;

// ...
// ... game logic goes here ...

requestAnimationFrame(update);
}
Expand Down

0 comments on commit c3e8f6e

Please sign in to comment.