Sign in to follow this  
Sawyer

Changing Physics Bounds for Animations

Recommended Posts

I have a sprite sheet of my games playable character.  

The frames consist of all possible actions the character can do, including two different attacks.

I want to change the physics bounds on different animations as my sprites positioning obviously changes with different animations.

I got PhysicsEditor expecting it could handle this but as far as I can see, it only works for single images.

Is there any solutions for this to help me get near pixel perfect collision?

Any help is appreciated as always

Share this post


Link to post
Share on other sites

I never tried it myself, but this is one possible solution I can come up with (if there are way better options in Phaser, please post below).

You can put multiple JSON strings with different names in one file. One string for each hitbox for each frame you have within your animation. Then for each frame you can just load in a new hitbox matching the frame.

Then you can set up something like this (I assumed you use P2JS):

objectName.body.clearShapes();

if (currentAnimation == "walk") {
   objectName.body.loadPolygon(loadedJSONFileName, walkHitboxName);
}

else if (currentAnimation == "fight") {
   objectName.body.loadPolygon(loadedJSONFileName, fightHitboxName);
}

Of course your version will be more complicated, as you have to deal with multiple frames within one animation, but I guess this should get you going :).

Share this post


Link to post
Share on other sites

Thanks Taggrin, I'll give it a try!

my main problem is that my walking animation is much narrower than my attack one, so it was putting collision way off when walking into walls and stuff but your way definitely sounds promising

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.