Sign in to follow this  
moe091

decrease collision box size

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!

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Awesome thanks a lot :). Just what I was looking for. And I'll definitely be posting my game in the next few days, it's playable now I just need to add some content and redo graphics.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.