Skip to content
Harsh Singh edited this page Dec 1, 2021 · 3 revisions

getDirection

It returns a Vector 2D Object and the movement input from keyboard are mapped to this object.

Example

import { getDirection } from './bottlecap/keyboard.js';
const direction = getDirection();

player.pos.x += direction.x * SPEED * dt;
player.pos.y += direction.y * SPEED * dt;

keyDown

Checks if a key is down

Example

import { keyDown, KEYS } from './bottlecap/keyboard.js';

if(keyDown(KEYS.SPACEBAR)) {
  player.jump();
}

Clone this wiki locally