Adding Sprites to the body using Box2d

2019-08-10 12:55发布

问题:

I am trying to create an app like a CutTheRope. In My game,if i cut the rope,then i want to add sprites to the individual broken bodies.how to accomplish it.

Thanks....

回答1:

It totally depends how you are breaking your b2Body. I will answer the question according to the most feasible way to break body which is by creating multiple Fixtures on a body. When your body breaks, you destroy a fixture from your main body and recreate that fixture into a new b2Body. In box2d, the "Body", "Fixture" and "Joint" classes allows you to store "userData". So you store the sprite for broken bodies in their respective fixtures and when the body is broken then you can get the sprites for broken bodies from their respective fixtures.

I hope you understand.