Reputation: 2745
I am trying to create a simple Android game using libGDX and physics.
As far as I can understand, we can "draw" physics body objects (box2d body objects) either by:
debugRenderer.render(world, camera.combined);
or by something like:
batch.begin();
sprite = (Sprite) circleBody.getUserData();
sprite.setPosition(circleBody.getPosition().x - (sprite.getWidth() /2) , circleBody.getPosition().y - (sprite.getHeight()/2));
sprite.setSize(45*2, 45*2);
sprite.draw(batch);
batch.end();
Can someone explain me the difference between the two?
I think its not ideal to use debugRenderer.render(...)
for release/production codes. Is it true?
Upvotes: 0
Views: 2034
Reputation: 19776
The difference is very simple. The Box2dDebugRenderer
is extremely simple to use. It basically requires just a single line of code (the one you already wrote in your question), and it will render simple shapes to visualize your Box2D World
. It will render coloured squares, circles, lines and points for Fixture
s, Joint
s or Contact
s.
The second approach you posted is completely selfmade. You can draw whatever you want for the Body
. You can draw a simple shape yourself, or a sprite, or maybe an animation or even a 3D model. Maybe even nothing.
That's the "problem" with Box2D. The World
you create is purely a physics world and Box2D does not know how to render anything, that's what you have to do yourself. A squared Fixture
attached to a Body
could be a wall, it could be a box or a door.
This other question on SO has a few pictures which show the difference when both rendering methods are used. (Unfortunately they are rendered on different places, which is what this quesion was about).
Upvotes: 4