I've implemented coins in my game, and to keep things consistent and to simplify collision detection, each coin is represented by a Box2D body. When there is a collision between the player and a coin, a flag in the coin object is set to true, which tells the game class that it should be removed. After calling world->Step(...), I remove the bodies via this line of code:
The coins are being removed fine, but there's a huge amount of lag. Even when just collecting one coin (so just one body being removed), it lags horribly.
If anyone could help me with this it'd be much appreciated!
Thanks guys.
Code:
entities_.erase(std::remove_if(entities_.begin(), entities_.end(), [](std::unique_ptr<Entity>& ent) { return ent->shouldRemove(); }), std::end(entities_));
The coins are being removed fine, but there's a huge amount of lag. Even when just collecting one coin (so just one body being removed), it lags horribly.
If anyone could help me with this it'd be much appreciated!
Thanks guys.