feat: on-screen buttons component
We have the buttons mapping in the initial KAPLAY options when you call kaplay(). These currently support keyboard/mouse and gamepad, however there is no support for piping clicks of on-screen areas to the simulated input buttons, you have to attach an onClick handler and do it yourself.
Could it be possible to add a button() component that depends on area(), that when it is clicked, it dispatches the specified onButtonDown etc. event handlers?
Example usage:
kaplay({
buttons: {
jump: { keyboard: ["space"], gamepad: ["south"] }
}
});
add([ // You can click this to jump
fixed(),
pos(),
rect(200, 100),
color(RED),
area(),
anchor("botright"),
button("jump"),
{ update() { this.pos = vec2(width() - 20, height() - 20); }
])
onButtonPress("jump", () => {
debug.log("Boing!");
});
I think sounds fine. I also was thinking on a custom function to trigger by yourself the press of buttons
this was addressed in #476... not sure how this didn't get closed with that