Jump to content


Recommended Posts

Hi. I'm trying to make my first game with Phaser and I'm trying to get some physics working - global gravity.

I'm not sure whats going on but somethings not working:


vaultage.game.prototype = {
  create : function() {
    this.background = this.game.add.tileSprite(0, 0, this.game.width, 360, 'background');
    this.background.autoScroll(-100, 0);

    this.background = this.game.add.tileSprite(0, 290, this.game.width, 8, 'ground');
    this.background.autoScroll(-180, 0);

    this.player = this.add.sprite(30, 230, 'player');
    this.player.animations.play('run', 10, true);

    // physics engine
    // gravity
    this.game.physics.p2.gravity.y = 400;


based on a couple tutorials I've been following I was expecting for the 'ground' to fall, but it does not. I'm still really new to Phaser and kinda new to JS, so i figure I'm overlooking something simple.

I actually only need gravity on the player sprite so if you could suggest how to go about that I would appreciate in but would be happy just to get some gravity of any kind to start with.

Thank you in advance for your help.   

Link to comment
Share on other sites

First, start this.game this.game.physics.startSystem(Phaser.Physics.P2JS); before you make the sprites or alternatively add physics to each sprite like this: this.game.physics.p2.enable(this.player);

Link to comment
Share on other sites


  • Recently Browsing   0 members

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