Jump to content

crffty
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...