jopcode Posted January 15, 2017 Share Posted January 15, 2017 Hi guys, i have a code for the double jump, but sometimes this don't work correctly and my player can't jump, I'm noob with phaser, and someone can help me to optimize my code please This is my code(jumpCound and jumpMax has been declared in create function): this.upKey = this.game.input.keyboard.addKey(Phaser.Keyboard.UP); if(this.upKey.downDuration(20)) { if(this.jumpCount < this.jumpMax) { this.jumpCount++; this.player.body.velocity.y = -500; console.log(this.jumpMax + ' ' + this.jumpCount); } } if(this.player.body.blocked.down || this.player.body.touching.down) { this.jumpCount = 0; } This code has been declared in UPDATE function Link to comment Share on other sites More sharing options...
Tom Atom Posted January 15, 2017 Share Posted January 15, 2017 Hi, yesterday I answered your similar question here: Link to comment Share on other sites More sharing options...
jopcode Posted January 15, 2017 Author Share Posted January 15, 2017 7 minutes ago, Tom Atom said: Hi, yesterday I answered your similar question here: I am very grateful, I hadn't seen that, I am checking right now. Link to comment Share on other sites More sharing options...
jopcode Posted January 15, 2017 Author Share Posted January 15, 2017 @Tom Atom With this code happen to something similar that with my code, sometimes I'm can't to double jump, only can jump one time, any idea? Link to comment Share on other sites More sharing options...
Tom Atom Posted January 15, 2017 Share Posted January 15, 2017 @jopcode - that code was taken from games in production. Only thing is here: this._nextJumpTime = this.game.time.time + 250; It prevents you to start next jump 250 millis after previous one. You may decrease it and see if it helps. What browser do you use for testing? Link to comment Share on other sites More sharing options...
jopcode Posted January 15, 2017 Author Share Posted January 15, 2017 @Tom Atom With Chrome, trying now decrease that Link to comment Share on other sites More sharing options...
jopcode Posted January 15, 2017 Author Share Posted January 15, 2017 @Tom Atom I solved it, using my code with only one variation in: if(this.upKey.downDuration(20)) changed it for : if(this.upKey.justDown) And the double jump work correctly, very thanks for you help <3 Link to comment Share on other sites More sharing options...
Recommended Posts