Skip to content

🕹️ Add virtual joystick in litecanvas games

License

Notifications You must be signed in to change notification settings

litecanvas/plugin-joystick

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

🕹️ Add virtual joystick in litecanvas games

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published