Jump to content

Why does allowGravity() affect all sprites?


Goshawk
 Share

Recommended Posts

I have two sprites `bunny` and `baddy`. I want gravity to enact on `bunny` but not `baddy`.

I understand that I can set `baddy.body.allowGravity()` to false but when I do this, gravity stops enacting on `bunny` too. I have discovered that it happens no matter whether I pass `true` or `false` to `allowGravity()` -- the result is always that gravity stops enacting on both sprites.

function create() {
    // create the player sprite
    bunny = this.physics.add.sprite(200, 200, 'bunny');
    bunny.body.setBounce(0.2); // our player will bounce from items
    bunny.body.setCollideWorldBounds(true); // don't go out of the map

    // create the baddy sprite
    baddy = this.physics.add.sprite(500,200, 'baddy');
    baddy.body.allowGravity(true); // This isn't working as I expect it to!!

    cursors = this.input.keyboard.createCursorKeys();
}

Am I doing anything obviously wrong? How do I prevent gravity enacting on `baddy` but not `bunny`?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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