Jump to content

Modifying polygon Shapes of animated sprite


harishkumarvijay
 Share

Recommended Posts

I'm trying to apply physics to a animated sprite. I used PhysicsEditor to generate the JSON and loaded the polygon shape for the first frame. 

Collision detection is not happening when i try to clear the shapes and load the polygon dynamically with respect to animation. 

Is there any method to clear and load the polygon dynamically to detect collision. 

Any thoughts ?

Link to comment
Share on other sites

HI I found a solution for the issue. Every time when I clear a shape from p2 physics body,  it looses its collision group settings.

So whenever we clear and load new shape we need to set the collision group again. This solved my issue.

Code Snippet:     

// Collision Group
var collisionGroup = game.physics.p2.createCollisionGroup();
 
// Removing the previously loaded or default shape 
sprite.body.clearShapes()
 
// Loading a new shape with respect to the sprite
sprite.body.loadPolygon(JSONData, name);
 
// Setting the collision group to the body
sprite.body.setCollisionGroup(collisionGroup)
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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