Replies: 1 comment
-
there's double jump in the "sticky" example where it's packed into a component (maybe i should just renamed it to "doublejump"): // custom component to handle double jump
function djump() {
let hasDouble = true;
return {
id: "djump",
// requires the "body" component
require: [ "body", ],
// runs once on add
add() {
this.on("grounded", () => {
hasDouble = true;
});
},
djump(...args) {
if (this.grounded()) {
this.jump(...args);
} else if (hasDouble) {
hasDouble = false;
this.jump(...args);
// triggers a custom event
this.trigger("djump");
}
},
};
}
// add player character
const player = add([
sprite("car"),
area(),
body(),
pos(),
// use our custom component here
djump(),
]);
// use the patched djump() instead of normal jump()
keyPress("space", () => {
player.djump();
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to get the player character to do a dumble jump when the character presses space while the character is already jumping. But it just keeps going:
`keyPress("space", () => {
// these 2 functions are provided by body() component
});`
Beta Was this translation helpful? Give feedback.
All reactions