@rbuljan/gamepad
Version:
Multi-touch gamepad with buttons and joystick for JavaScript games, apps, IOT
37 lines (27 loc) • 677 B
text/typescript
import { Controller } from "./controller";
import { ControllerOptions } from "./ControllerOptions";
/**
* Gamepad - Button Controller
*/
export class Button extends Controller {
constructor(options: ControllerOptions) {
super(options, "button");
}
onStart() {
super.onStart();
this.state.value = this.options.spring
? 1
: this.state.isActive
? 1
: 0;
this.onInput();
}
onEnd() {
super.onEnd();
if (!this.options.spring) {
return;
}
this.state.value = 0;
this.onInput();
}
}