Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: on-screen buttons component #412

Open
dragoncoder047 opened this issue Sep 19, 2024 · 1 comment
Open

feat: on-screen buttons component #412

dragoncoder047 opened this issue Sep 19, 2024 · 1 comment

Comments

@dragoncoder047
Copy link
Contributor

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!");
});
@lajbel
Copy link
Collaborator

lajbel commented Sep 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants