hotgeart Posted October 16, 2014 Share Posted October 16, 2014 Hi,Sorry for my bad english.I'm new in the world of html5 game and I'm trying to follow the tutorial from the book. I've an issue, I can't jump. I've no idea why.A link for testing : http://not more online If you look at the console, it's detecting the key up and if the player is touching the floor. But not the "JUMP!" and the velocity Y of course.The code ( from : http://not more online ) : Line 57if (this.cursor.up.isDown && this.player.body.touching.down) { console.log('JUMP!'); this.player.body.velocity.y = -320;}Thanks for your help. Link to comment Share on other sites More sharing options...
nkholski Posted October 16, 2014 Share Posted October 16, 2014 You need to add "this.cursor = this.input.keyboard.createCursorKeys();" in the create-function or "this.cursor" will be undefined. Link to comment Share on other sites More sharing options...
hotgeart Posted October 16, 2014 Author Share Posted October 16, 2014 Cursor is defined, I can move the player but the jump doesn't work. Link to comment Share on other sites More sharing options...
j0hnskot Posted October 16, 2014 Share Posted October 16, 2014 Could you try changing " this.player.body.touching.down " in your UP key check with "this.player.body.blocked.down" ? Link to comment Share on other sites More sharing options...
chg Posted October 16, 2014 Share Posted October 16, 2014 Change: update: function() { this.movePlayer(); game.physics.arcade.collide(this.player, this.walls);to: update: function() { game.physics.arcade.collide(this.player, this.walls); this.movePlayer(); j0hnskot 1 Link to comment Share on other sites More sharing options...
hotgeart Posted October 16, 2014 Author Share Posted October 16, 2014 Ok it's work. Can you explain the problem ? thx Link to comment Share on other sites More sharing options...
chg Posted October 16, 2014 Share Posted October 16, 2014 Ok it's work. Can you explain the problem ? thxYou were checking this.player.body.touching.down before you called the Arcade Physics collide() method, thus it was always false when you checked it in your jumping code. Until you call collide() the Player object's body is not tested for touching anything... Link to comment Share on other sites More sharing options...
j0hnskot Posted October 16, 2014 Share Posted October 16, 2014 This is because each frame the touching object gets reset to false. You were checking if the player is touching down before physics did the check for that, resulting to false. Link to comment Share on other sites More sharing options...
Recommended Posts