First you have to add your jump animation to the animation component. You can find this animation component on the Model entity that is a child of your Player entity. Rename the animation to ‘Jump’.
To play this animation replace the checkButtons function with the code below. In this code I have added on two places the jump state and disable the loop option before. I enable the loop option again on two two other places. I have not tested this, so let me know if you have a problem.
PlayerAnimationHandler.prototype.checkButtons = function () {
var app = this.app;
var w = app.keyboard.isPressed(pc.KEY_W);
var a = app.keyboard.isPressed(pc.KEY_A);
var s = app.keyboard.isPressed(pc.KEY_S);
var d = app.keyboard.isPressed(pc.KEY_D);
var space = app.keyboard.isPressed(pc.KEY_SPACE);
if (w && !s) {
if (space) {
this.entity.animation.loop = false;
this.direction = 'Jump';
} else if (a && !d) {
this.direction = 'Run Forward Left';
} else if (d && !a) {
this.direction = 'Run Forward Right';
} else {
this.entity.animation.loop = true;
this.direction = 'Run Forward';
}
} else if (s && !w) {
if (a && !d) {
this.direction = 'Run Backward Left';
} else if (d && !a) {
this.direction = 'Run Backward Right';
} else {
this.direction = 'Run Backward';
}
} else if (a && !d) {
this.direction = 'Run Left';
} else if (d && !a) {
this.direction = 'Run Right';
} else if (space) {
this.entity.animation.loop = false;
this.direction = 'Jump';
} else {
this.entity.animation.loop = true;
this.direction = 'Idle';
}
};