kaplay icon indicating copy to clipboard operation
kaplay copied to clipboard

feat: on-screen buttons component

Open dragoncoder047 opened this issue 1 year ago • 1 comments

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!");
});

dragoncoder047 avatar Sep 19 '24 17:09 dragoncoder047

I think sounds fine. I also was thinking on a custom function to trigger by yourself the press of buttons

lajbel avatar Sep 20 '24 01:09 lajbel

this was addressed in #476... not sure how this didn't get closed with that

dragoncoder047 avatar Oct 30 '24 22:10 dragoncoder047