Jump to content

decrease collision box size


moe091
 Share

Recommended Posts

Is there any way to decrease the size of the bounding box used for collisions in phaser? Right now I am just implementing my own collision inside phasers callback, essentially using phasers collision as a (slightly)-broad phase collision detection but it'd be cleaner and more efficient if I could just scale the collision box somehow without scaling the actual sprite.

 

Honestly I'm not sure which version of phaser I'm currently using, I downloaded it about a month and a half ago and didn't even pay much attention to it because I didn't expect to make any serious games yet. my current project was just too much fun and I blew it up into a big game(by html5 mobile game standards).

 

Anyway, thanks for any help. And thanks to Rich and everyone who worked on Phaser, it's awesome to work with!

Link to comment
Share on other sites

Change the body width / height of the sprite:

    this.sprite.body.width = 46;    this.sprite.body.height = 82;

Check if it works by displaying the collision box for the sprite:

game.debug.renderPhysicsBody(this.player.sprite.body);

You must set phaser to CANVAS Mode to get the debug outputs.

var game = new Phaser.Game(1280, 768, Phaser.CANVAS , '', null);

 

Good luck, and don't forget to post your game here on the forums when it's either done or playable and you want feedback.

Link to comment
Share on other sites

  • 2 years later...

Just an update on this, the API has changed.

In the latest version of Phaser (as of May 2016), you should use the following to display the sprite's collision hitbox:

game.debug.body(sprite);

Also, remember to put this into the render() function.

Link to comment
Share on other sites

  • 3 years later...
this.sprite.body.width = 32;

I have one question:

if I decrease the width of the sprite for example - from 48u to 32u then collision moves by 16u left - how could I center (align) the colission? (8u to left and 8u to right)

u - unit

Link to comment
Share on other sites

  • 3 weeks later...
 Share

  • Recently Browsing   0 members

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