joystick
install
pnpm add joystick-kit
dome
import Joystick from "joystick-kit";
/* create instance */
const joystick = new Joystick();
/* create joystick */
joystick.create({ zone: "joystick" });
/* event */
joystick.on("start", () => {
console.log("start ===> ");
});
API
create
interface CreateConfig {
mode: string; // ๆ่ฝฝๆจกๅผ static | dynamic
zone: string; // ๆ่ฝฝ่็น
size?: number; // ๆๆๅคงๅฐ
position: { top: string; left: string; right: string; bottom: string }; //็ปไปถๅฎไฝ dynamic ๆจกๅผไธๆ ๆ
color?: { back: string; front: string }; // ๆๆ้ข่ฒ
backImg?: { back: string; front: string }; // ๆๆ่ๆฏๅพ
}
backImg ไผๅ ไบ color
on
// event keys
interface EventType {
start: string;
move: string;
end: string;
}
// event params
interface MoveInfo {
direction: string;
ang: number;
}
interface EventObj {
start: null | ((Event, Joystick) => void);
move: null | ((Event, { direction, ang }: MoveInfo) => void);
end: null | ((Event, Joystick) => void);
}