Package Exports
- @hmans/controlfreak
- @hmans/controlfreak/dist/hmans-controlfreak.cjs.js
- @hmans/controlfreak/dist/hmans-controlfreak.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@hmans/controlfreak) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
CONTROL FREAK
tl;dr
Add it to your project:
yarn add @hmans/controlfreakWrite a module that composes and exports your game controller, eg controller.ts:
import {
BooleanControl,
Controller,
GamepadDevice,
KeyboardDevice,
processors,
TouchDevice,
VectorControl
} from "@hmans/controlfreak"
export const controller = new Controller()
const keyboard = new KeyboardDevice()
const gamepad = new GamepadDevice()
const touch = new TouchDevice()
controller.addDevice(keyboard)
controller.addDevice(gamepad)
controller.addDevice(touch)
controller
.addControl("move", VectorControl)
.addStep(keyboard.compositeVector("KeyW", "KeyS", "KeyA", "KeyD"))
.addStep(gamepad.axisVector(0, 1))
.addStep(processors.clampVector(1))
controller
.addControl("fire", BooleanControl)
.addStep(keyboard.whenKeyPressed(["Space", "Enter"]))
.addStep(gamepad.whenButtonPressed(0))
controller
.addControl("aim", VectorControl)
.addStep(
keyboard.compositeVector("ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight")
)
.addStep(gamepad.axisVector(2, 3))
.addStep(processors.normalizeVector)
controller.onDeviceChange.add((d) => console.log("new device:", d))Then use it in your game loop:
import { controller } from "./controller"
/* Very likely within some sort of loop...: */
controller.update()
console.log(controller.controls.move.value)