Game Development Reference
In-Depth Information
A screenshot of Box2D's view of the rock bodies is as follows:
The thin blue lines forming a rectangle visualizes how (the shape) and where (the
position) Box2D sees each rock. These lines have been rendered with the help of
Box2D's Box2DDebugRenderer class. Let's add this feature to the game code so that it
can be quickly enabled when needed.
Add the following import line to the WorldRenderer class:
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
After this, add the following lines of code to the same class:
private static final boolean DEBUG_DRAW_BOX2D_WORLD = false;
private Box2DDebugRenderer b2debugRenderer;
Then, make the following changes to the same class:
private void init () {
batch = new SpriteBatch();
camera = new OrthographicCamera(Constants.VIEWPORT_WIDTH,
Constants.VIEWPORT_HEIGHT);
camera.position.set(0, 0, 0);
camera.update();
cameraGUI = new OrthographicCamera(Constants.VIEWPORT_GUI_WIDTH,
Constants.VIEWPORT_GUI_HEIGHT);
cameraGUI.position.set(0, 0, 0);
cameraGUI.setToOrtho(true);
// flip y-axis
cameraGUI.update();
 
Search WWH ::




Custom Search