Skip to content

Unified Input and Input Bindings

Daniel Báez edited this page Jun 14, 2024 · 2 revisions

Unified Input and Input Bindings

#142

API

Defining input bindings in CONFIG

kaplay({
    // Define buttons
    buttons: {
        up: { keyboard: ["w", "up"], controller: ["dpad-up"] },
    },
    saveButtons: true, // save them in localStorage? (idea)
});

Setting and getting input bindings in runtime

setButton("up", {
    keyboard: ["w"],
    controller: ["dpad-up"],
});

getButton("up") // get the up bindings 

Using input bindings

onButtonPress("up") // work as onGamepadButtonPress("dpad-up") and onKeyPress("up")
onButtonDown("up")
onButtonRelease("up")
Clone this wiki locally