Last active
January 2, 2016 20:59
-
-
Save kotcrab/8360067 to your computer and use it in GitHub Desktop.
Box2dTutorial - Code 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pl.kotcrab.libgdxtests; | |
import com.badlogic.gdx.ApplicationListener; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.graphics.GL10; | |
import com.badlogic.gdx.graphics.OrthographicCamera; | |
import com.badlogic.gdx.math.Vector2; | |
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer; | |
import com.badlogic.gdx.physics.box2d.World; | |
public class Box2dTester implements ApplicationListener | |
{ | |
private OrthographicCamera camera; | |
static final float WORLD_TO_BOX = 0.01f; | |
static final float BOX_TO_WORLD = 100f; | |
private World world; | |
private Box2DDebugRenderer debugRenderer; | |
@Override | |
public void create() | |
{ | |
camera = new OrthographicCamera(800, 480); | |
camera.position.x = 400; | |
camera.position.y = 240; | |
camera.update(); | |
world = new World(new Vector2(0, -10), true); | |
debugRenderer = new Box2DDebugRenderer(); | |
} | |
@Override | |
public void render() | |
{ | |
Gdx.gl.glClearColor(0, 0, 0, 1); | |
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); | |
camera.update(); | |
world.step(1 / 60f, 6, 2); | |
debugRenderer.render(world, camera.combined.scl(BOX_TO_WORLD)); | |
} | |
@Override | |
public void dispose() | |
{ | |
world.dispose(); | |
} | |
//@formatter:off | |
@Override public void pause(){} | |
@Override public void resume(){} | |
@Override public void resize(int width, int height){} | |
//@formatter:on | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment