I am working on an iOS endless-running game (Robot Unicorn, Canabalt, etc). I'm using box2d for the Physics and Collision Checking and cocos2d for graphics.
To achieve the notion of an endless level, I instantiate "boards" which encapsulate a set of box2d bodies (floors, enemies, etc). I place two of these "boards" alongside and I check for their current position every frame. When they leave the visible area of the iPhone screen, I move the board and it's set of bodies to a new position, further ahead.
To do this I use the SetTransform() method of the b2Body class.
I also put all my bodies to sleep before doing this.
My issue is that every time I perform this task, the FPS has a noticeable drop.
I ran the Profiler and it seems the problem is within the SetTransform(). Apparently, box2d is removing and inserting leafs in the dynamic tree.
I am moving around 50 bodies in one frame.
My question to you guys is if anyone knows of a more convenient way to translate bodies without it taking a toll in performance. Perhaps it's cheaper to create new bodies, instead of moving the existing ones? Am I missing some kind of flag I should activate before calling SetTransform()?
Thanks in advance!