crffty Posted November 27, 2016 Share Posted November 27, 2016 I'm working on a endless runner as my first adventure into phaser but am having some trouble with getting my player sprite to jump. vaultage.game = function() {}; vaultage.game.prototype = { create : function() { // physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 500; // sprites this.ground = this.game.add.tileSprite(0, 290, this.game.width, 8, 'ground'); this.ground.autoScroll(-180, 0); this.player = this.add.sprite(45, 200, 'player'); this.player.animations.add('run'); this.player.animations.play('run', 15, true); // physics on sprites this.game.physics.arcade.enable([this.player, this.ground]); this.ground.body.immovable = true; this.ground.body.allowGravity = false; this.player.body.collideWorldBounds = true; // input cursors = game.input.keyboard.createCursorKeys(); jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); }, update : function() { this.game.physics.arcade.collide(this.player, this.ground); if (jumpButton.isDown && this.player.body.touching.down() && game.time.now > jumpTimer) { player.body.velocity.y = -100; jumpTimer = game.time.now + 500; } }, shutdown : function() { } } i think its a problem with the way i've write " this.player.bady.touching.down " but I've tried it a couple ways. I'm mostly new to JS so I'm sure its a me problem but some help would be greatly appreciated. Thank you. Link to comment Share on other sites More sharing options...
CharlesCraft50 Posted November 27, 2016 Share Posted November 27, 2016 I only use this code to jump my player, try this: if (jumpButton.isDown && (player.body.onFloor() || player.body.touching.down)) { player.body.velocity.y = -100; } Link to comment Share on other sites More sharing options...
crffty Posted November 27, 2016 Author Share Posted November 27, 2016 41 minutes ago, CharlesCraft50 said: awesome! thank you!!! CharlesCraft50 1 Link to comment Share on other sites More sharing options...
Recommended Posts