- package com.aftersomemath.Screens;
- import World.ObjectManager;
- import World.Renderer;
- import com.badlogic.gdx.Screen;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.math.Vector2;
- import com.badlogic.gdx.physics.box2d.Body;
- import com.badlogic.gdx.physics.box2d.BodyDef;
- import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
- import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
- import com.badlogic.gdx.physics.box2d.CircleShape;
- import com.badlogic.gdx.physics.box2d.Fixture;
- import com.badlogic.gdx.physics.box2d.FixtureDef;
- import com.badlogic.gdx.physics.box2d.PolygonShape;
- import com.badlogic.gdx.physics.box2d.World;
- public class TestBox2d implements Screen {
- private ObjectManager objects;
- private Renderer renderer;
- private float runTime;
- private World world = new World(new Vector2(0, -10), true);
- private Box2DDebugRenderer debugRenderer = new Box2DDebugRenderer();
- private OrthographicCamera camera;
- public TestBox2d() {
- camera = new OrthographicCamera();
- camera.setToOrtho(true, 20.0f, 20.0f);
- // First we create a body definition
- BodyDef bodyDef = new BodyDef();
- // We set our body to dynamic, for something like ground which doesn't move we would set it to StaticBody
- bodyDef.type = BodyType.DynamicBody;
- // Set our body's starting position in the world
- bodyDef.position.set(10, 15);
- // Create our body in the world using our body definition
- Body body = world.createBody(bodyDef);
- // Create a circle shape and set its radius to 6
- CircleShape circle = new CircleShape();
- circle.setRadius(6f);
- // Create a fixture definition to apply our shape to
- FixtureDef fixtureDef = new FixtureDef();
- fixtureDef.shape = circle;
- fixtureDef.density = 0.5f;
- fixtureDef.friction = 0.4f;
- fixtureDef.restitution = 0.6f; // Make it bounce a little bit
- // Create our fixture and attach it to the body
- Fixture fixture = body.createFixture(fixtureDef);
- // Remember to dispose of any shapes after you're done with them!
- // BodyDef and FixtureDef don't need disposing, but shapes do.
- circle.dispose();
- // Create our body definition
- BodyDef groundBodyDef =new BodyDef();
- // Set its world position
- groundBodyDef.position.set(new Vector2(0, 10));
- // Create a body from the defintion and add it to the world
- Body groundBody = world.createBody(groundBodyDef);
- // Create a polygon shape
- PolygonShape groundBox = new PolygonShape();
- // Set the polygon shape as a box which is twice the size of our view port and 20 high
- // (setAsBox takes half-width and half-height as arguments)
- groundBox.setAsBox(camera.viewportWidth, 10.0f);
- // Create a fixture from our polygon shape and add it to our ground body
- groundBody.createFixture(groundBox, 0.0f);
- // Clean up after ourselves
- groundBox.dispose();
- }
- public void show() {
- }
- @Override
- public void render(float delta) {
- debugRenderer.render(world, camera.combined);
- world.step(1/10f, 6, 2);
- }
- @Override
- public void resize(int width, int height) {
- }
- @Override
- public void hide() {
- // TODO Auto-generated method stub
- }
- @Override
- public void pause() {
- // TODO Auto-generated method stub
- }
- @Override
- public void resume() {
- // TODO Auto-generated method stub
- }
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
- }
- }
SHARE
TWEET
Untitled
a guest
Sep 13th, 2014
163
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
