@litecanvas/plugin-joystick
v0.5.0
Published
Virtual joystick for litecanvas games based on NippleJS
Downloads
3
Maintainers
Readme
Joystick plugin for litecanvas
Adds a virtual joystick to litecanvas games.
Install
NPM: npm i @litecanvas/plugin-joystick
CDN: https://unpkg.com/@litecanvas/plugin-joystick/dist/dist.js
Basic Usage
import litecanvas from "litecanvas"
import pluginJoystick from "@litecanvas/plugin-joystick"
litecanvas({
loop: { init, update, draw },
})
use(pluginJoystick) // load the plugin
actor = {
x: CENTERX,
y: CENTERY,
speed: 100,
}
function update(dt) {
if (JOYSTICK.active) {
const force = min(JOYSTICK.force, 2)
actor.x += actor.speed * force * cos(JOYSTICK.angle) * dt
actor.y += actor.speed * force * sin(JOYSTICK.angle) * dt
}
}
function draw() {
cls(1)
circfill(actor.x, actor.y, 32, 6)
}
See this demo in litecanvas playground
For more details, check the demo.