Jump to content

Changing Physics Bounds for Animations


Sawyer
 Share

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

Link to comment
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 :).

Link to comment
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

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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