Using box2d DrawDebugData with multi layer scene ?
Posted
by
Mr.Gando
on Game Development
See other posts from Game Development
or by Mr.Gando
Published on 2011-02-22T01:00:21Z
Indexed on
2011/02/22
7:33 UTC
Read the original article
Hit count: 269
2d-physics
|box2d
In my Game, a Scene is composed by several layers. Each layer has different camera transformations.
This way I can have a layer at z=3 (GUI), z=2 (Monsters), z=1 (scrolling background), and this 3 layers compose my whole Scene.
My render loop looks something like:
renderLayer()
applyTransformations()
renderVisibleEntities()
renderChildLayers()
end
If I call DrawDebugData()
in the render loop, the whole b2world debug data will be rendered once for each layer in my scene, this generates a mess, because the "debug boxes" get duplicated, some of them get the camera transformations applied and some of them don't, etc.
What I would like to do, would be to make DrawDebugData to draw only certain debug boxes. In that way, I could call something like
b2world->DrawDebugDataForLayer(int layer_id)
and call that on each layer like :
renderLayer()
applyTransformations()
renderVisibleEntities()
//Only render my corresponding layer debug data
b2world->DrawDebugDataForLayer(layer_id)
renderChildLayers()
end
Is there a way to subclass b2World
so I could add this functionality ( specific to my game ) ?
If not, what would be the best way to achieve this (Cocos2d uses a similar scene graph approach and box2d, but I'm not sure if debugDraw works in Cocos2d... )
Thanks
© Game Development or respective owner