0.5.0 • Published 11 months ago

@litecanvas/plugin-joystick v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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.

0.5.0

11 months ago

0.3.0

1 year ago

0.4.1

1 year ago

0.2.3

1 year ago

0.4.0

1 year ago

0.4.2

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago