Reputation: 87
I Added the coins on the track of user by creating a Sprite, which i kept in a Body. The problem is when the player collide with coin, the coin removed but it takes a jerk for nano second. I want the player to run smooth even when he collides with the coin.
Upvotes: 1
Views: 286
Reputation: 6895
You are correct, the problem is due to Box2D. Obviously, removing a body takes some time and causes some delay. If you don't plan to have a very large number of bodies you can just keep them the whole time, you can attach a sensor to the body. Sensor is a special kind of fixture that does not cause collisions with other bodies but you can find out whether the bodies are touching. This way you could keep the coins in their place and only remove the Sprite so that the coin will disappear without the overhead caused by removing a body.
See the Box2d manual here: http://www.box2d.org/manual.html#_Toc258082972
Another thing is collision filtering, although I am not certain whether the isTouching() method would return true if the collision bits are set up appropriately, so you'll have to try that. There is a nice tutorial here: http://www.iforce2d.net/b2dtut/collision-filtering
Upvotes: 1