I used an example from phaser.io (click here) and tried to edit it to make my own game, but once I tried adding a jump/fall animation I ran into a problem (my code here)
Code snpipet
if (cursors.up.isDown && player.body.touching.down) {
player.setVelocityY(-330);
if (player.VelocityY < 0) {
cosnole.log('jumping');
player.anims.play('jump', true);
}
if (player.VelocityY >= 0) {
console.log('falling');
player.anims.play('fall', true);
} else {
console.log('FAILED');
console.log(player.VelocityY);
}
}
Gave me the output “FAILED” and then “undefined”, but my player still jumps.
How is it possible that the code uses a not existing value without running into an error?
maybe its because you put an extra true after player.anims.play(‘jumping’) and player .anims.play(‘fall’) or you wrote cosnole.log(“jumping”) instead of console.log("jumping).
if (player.body.touching.down) {
// On floor.
if (cursors.up.isDown) {
player.setVelocityY(-330);
player.anims.play('jump');
}
} else {
// In the air.
if (player.body.velocity.y >= 0) {
player.anims.play('fall', true);
}
}