Example usage for com.badlogic.gdx.physics.box2d Box2DDebugRenderer Box2DDebugRenderer

List of usage examples for com.badlogic.gdx.physics.box2d Box2DDebugRenderer Box2DDebugRenderer

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d Box2DDebugRenderer Box2DDebugRenderer.

Prototype

public Box2DDebugRenderer() 

Source Link

Usage

From source file:Tabox2D.java

License:Open Source License

private Tabox2D(Vector2 gravity) {
    width = Gdx.graphics.getWidth();//  www.  jav  a  2 s  . co m
    height = Gdx.graphics.getHeight();
    meterSize = 100;// 1 metter = 100px, default.
    polyInfo = new HashMap<String, Float>();
    rawForces = false;

    // Sides by polygon:
    polyInfo.put("triangle", 3f);
    polyInfo.put("square", 4f);
    polyInfo.put("pentagon", 5f);
    polyInfo.put("hexagon", 6f);
    polyInfo.put("heptagon", 7f);
    polyInfo.put("octagon", 8f);

    // Angle of the sides:
    polyInfo.put("triangle_angle", 120f);
    polyInfo.put("square_angle", 90f);
    polyInfo.put("pentagon_angle", 72f);
    polyInfo.put("hexagon_angle", 60f);
    polyInfo.put("heptagon_angle", 51.428f);
    polyInfo.put("octagon_angle", 45f);

    filterMin = "linear";
    filterMag = "linear";

    renderer = new Box2DDebugRenderer();
    sr = new ShapeRenderer();
    spriteBath = new SpriteBatch();
    adjustCamera();
    tabodies = new ArrayList<Tabody>();
    world = new World(new Vector2(gravity.x, gravity.y), true);

    sr = new ShapeRenderer();
}

From source file:be.ac.ucl.lfsab1509.bouboule.game.gameManager.GameLoop.java

License:Open Source License

/**
 * Launch the creation of the batch thanks to the camera. if debug == true,
 * set up the debugger matrix/*from   w  w w  .  j  a  v  a  2 s . c o m*/
 * 
 * @param cam    : the OrthographicCamera of the game
 * @param debug : load the debugging matrix
 * 
 * GameLoop(OrthographicCamera cam, boolean debug)
 */
public GameLoop(final OrthographicCamera cam, final boolean debug) {

    // creation of the batch and matrix (physical edges of the bodies)
    // debugger
    batch = new SpriteBatch();
    batch.setProjectionMatrix(cam.combined);

    if (debug) {
        debugMatrix = new Matrix4(cam.combined);
        debugMatrix.scale(GraphicManager.getGameToWorld(), GraphicManager.getGameToWorld(), 1f);

        debugRenderer = new Box2DDebugRenderer();
    }

    // Create only once the graphicManager
    graphicManager = new GraphicManager();

    // Load the font
    fontOswald = new BitmapFont(Gdx.files.internal("fonts/Oswald/Oswald.fnt"),
            Gdx.files.internal("fonts/Oswald/Oswald.png"), false);
    fontOsaka = new BitmapFont(Gdx.files.internal("fonts/Osaka/Osaka.fnt"),
            Gdx.files.internal("fonts/Osaka/Osaka.png"), false);

    fontOsakaRed = new BitmapFont(Gdx.files.internal("fonts/Osaka/Osaka.fnt"),
            Gdx.files.internal("fonts/Osaka/Osaka.png"), false);
    fontOsakaRed.setColor(.95f, .05f, .05f, 1f);

    // Pause
    if (GlobalSettings.GAME.isGdxMenus()) {
        fontPause = new BitmapFont(Gdx.files.internal("fonts/OsakaBig/OsakaBig.fnt"),
                Gdx.files.internal("fonts/OsakaBig/OsakaBig.png"), false);
        fontPause.setColor(.95f, .05f, .05f, 1f);
        texturePause = new Texture("buttons/home_button.png");
        pixmapFade = new Pixmap(1, 1, Format.RGB888);
        spriteFade = new Sprite(new Texture(pixmapFade));
        spriteFade.setColor(0, 0, 0, 0);
        spriteFade.setSize(GlobalSettings.APPWIDTH * 2, GlobalSettings.APPHEIGHT * 2); // bigger size to cover all the zone
        spriteFade.setPosition(-GlobalSettings.APPWIDTH / 2, -GlobalSettings.APPHEIGHT / 2);
    }

    // load the counter
    countDown = new CountDown(2, 2, 1f, "anim/countdown.png", true); // 3 sec

    // new randomGenerator
    random = new Random();
}

From source file:com.agateau.pixelwheels.racescreen.GameRenderer.java

License:Open Source License

public GameRenderer(GameWorld world, Batch batch, PerformanceCounters counters) {
    mDebugRenderer = new Box2DDebugRenderer();
    mWorld = world;/*from ww  w.  jav a2s.  c o m*/

    mTrack = mWorld.getTrack();

    mExtraBackgroundLayerIndexes = mTrack.getExtraBackgroundLayerIndexes();
    mForegroundLayerIndexes = mTrack.getForegroundLayerIndexes();

    mBatch = batch;
    mCamera = new OrthographicCamera();
    boolean singlePlayer = mWorld.getPlayerRacers().size == 1;
    mCameraUpdater = singlePlayer ? new SinglePlayerCameraUpdater(mWorld)
            : new MultiPlayerCameraUpdater(mWorld);
    mRenderer = new OrthogonalTiledMapRenderer(mTrack.getMap(), Constants.UNIT_FOR_PIXEL, mBatch);

    mTilePerformanceCounter = counters.add("- tiles");
    mGameObjectPerformanceCounter = counters.add("- g.o.");

    mDebugRenderer.setDrawVelocities(Debug.instance.drawVelocities);
}

From source file:com.barconr.games.marblegame.Maze2Drenderer.java

License:Apache License

public Maze2Drenderer(TiledMap tm, Physics2D physics) {
    font = new BitmapFont();
    this.physics = physics;
    renderer = new Box2DDebugRenderer();
    ballLoc = new Vector2();
    map = tm;//from w  w w. ja v a2  s. c o  m

    camera = new OrthographicCamera(Assets.VIRTUAL_SCREEN_WIDTH, Assets.VIRTUAL_SCREEN_HEIGHT);
    camera.position.set(Assets.VIRTUAL_SCREEN_WIDTH / 2f, Assets.VIRTUAL_SCREEN_HEIGHT / 2f, 0);
    camera.update();

    //Load Marble Sprite
    marbleSprite = new Sprite(Assets.marble);
    marbleSprite.setBounds(0, 0, 16, 16);

    tilerender = new OrthogonalTiledMapRenderer(map);

    //createFixtures(Assets.mazemap);

    debugProj = new Matrix4(camera.combined);
    debugProj.scale(Assets.PIXELS_PER_METER, Assets.PIXELS_PER_METER, 1);
    batcher = new SpriteBatch();

    batcher.setProjectionMatrix(camera.combined);
    batcher.enableBlending();

    tilerender.setView(camera);

}

From source file:com.disc.jammers.states.StatePlay.java

public StatePlay(GameStateManager gsm) {
    super(gsm);// ww  w  .  ja  v  a2 s.  c  o  m
    eventQueue = new EventQueue();

    camera.setToOrtho(false, WIDTH, HEIGHT);
    Gdx.input.setInputProcessor(new MyInputProcessor(eventQueue));

    //Box2d Initialization
    world = new World(new Vector2(0, 0), true);
    world.setContactListener(new MyContactListener(eventQueue));
    b2dr = new Box2DDebugRenderer();

    manager = new GameManager(world, eventQueue);
    //--Sprites

    createBoxBoundaries();
    tempBackground = new Texture("court.png");
}

From source file:com.dongbat.game.system.localSystem.Box2dDebugRendererSystem.java

@Override
protected void initialize() {
    box2DDebugRenderer = new Box2DDebugRenderer();
    physicWorld = PhysicsUtil.getPhysicsWorld(world);
    camera = PhysicsCameraUtil.getCamera();
}

From source file:com.dongbat.game.util.localUtil.DebugRendererFactory.java

/**
 * Initialize box2d debug renderer/*from  w  ww  .ja v a 2s  .c  o  m*/
 */
public static void init() {
    if (debugRenderer == null) {
        debugRenderer = new Box2DDebugRenderer();
    }
}

From source file:com.dongbat.invasion.system.Box2DDebugRenderSystem.java

@Override
protected void initialize() {
    box2DDebugRenderer = new Box2DDebugRenderer();
    physicWorld = PhysicsUtil.getWorld();
    camera = PhysicsCameraUtil.getCamera();
}

From source file:com.esotericsoftware.spine.Box2DExample.java

License:Open Source License

public void create() {
    batch = new SpriteBatch();
    renderer = new ShapeRenderer();
    skeletonRenderer = new SkeletonRenderer();
    skeletonRenderer.setPremultipliedAlpha(true);

    atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy.atlas"));

    // This loader creates Box2dAttachments instead of RegionAttachments for an easy way to keep
    // track of the Box2D body for each attachment.
    AtlasAttachmentLoader atlasLoader = new AtlasAttachmentLoader(atlas) {
        public RegionAttachment newRegionAttachment(Skin skin, String name, String path) {
            Box2dAttachment attachment = new Box2dAttachment(name);
            AtlasRegion region = atlas.findRegion(attachment.getName());
            if (region == null)
                throw new RuntimeException("Region not found in atlas: " + attachment);
            attachment.setRegion(region);
            return attachment;
        }/* w  w  w.  ja  v  a 2  s  . c  om*/
    };
    SkeletonJson json = new SkeletonJson(atlasLoader);
    json.setScale(0.6f * 0.05f);
    SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy.json"));
    animation = skeletonData.findAnimation("walk");

    skeleton = new Skeleton(skeletonData);
    skeleton.x = -32;
    skeleton.y = 1;
    skeleton.updateWorldTransform();

    // See Box2DTest in libgdx for more detailed information about Box2D setup.
    camera = new OrthographicCamera(48, 32);
    camera.position.set(0, 16, 0);
    box2dRenderer = new Box2DDebugRenderer();
    createWorld();

    // Create a body for each attachment. Note it is probably better to create just a few bodies rather than one for each
    // region attachment, but this is just an example.
    for (Slot slot : skeleton.getSlots()) {
        if (!(slot.getAttachment() instanceof Box2dAttachment))
            continue;
        Box2dAttachment attachment = (Box2dAttachment) slot.getAttachment();

        PolygonShape boxPoly = new PolygonShape();
        boxPoly.setAsBox(attachment.getWidth() / 2 * attachment.getScaleX(),
                attachment.getHeight() / 2 * attachment.getScaleY(),
                vector.set(attachment.getX(), attachment.getY()), attachment.getRotation() * MathUtils.degRad);

        BodyDef boxBodyDef = new BodyDef();
        boxBodyDef.type = BodyType.StaticBody;
        attachment.body = world.createBody(boxBodyDef);
        attachment.body.createFixture(boxPoly, 1);

        boxPoly.dispose();
    }
}

From source file:com.example.jumpertutorial.JumperTutorial.java

License:Apache License

@Override
public void create() {
    /**//from w ww  .j  av  a  2s.  c o m
     * If the viewport's size is not yet known, determine it here.
     */
    if (screenWidth == -1) {
        screenWidth = Gdx.graphics.getWidth();
        screenHeight = Gdx.graphics.getHeight();
    }

    tiledMapHelper = new TiledMapHelper();

    tiledMapHelper = new TiledMapHelper();

    tiledMapHelper.setPackerDirectory("data/packer");

    tiledMapHelper.loadMap("data/world/level1/level.tmx");

    tiledMapHelper.prepareCamera(screenWidth, screenHeight);

    /**
     * Load up the overall texture and chop it in to pieces. In this case,
     * piece.
     */
    overallTexture = new Texture(Gdx.files.internal("data/sprite.png"));
    overallTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    jumperSprite = new Sprite(overallTexture, 0, 0, 21, 37);

    spriteBatch = new SpriteBatch();

    /**
     * You can set the world's gravity in its constructor. Here, the gravity
     * is negative in the y direction (as in, pulling things down).
     */
    world = new World(new Vector2(0.0f, -10.0f), true);

    BodyDef jumperBodyDef = new BodyDef();
    jumperBodyDef.type = BodyDef.BodyType.DynamicBody;
    jumperBodyDef.position.set(1.0f, 3.0f);

    jumper = world.createBody(jumperBodyDef);

    /**
     * Boxes are defined by their "half width" and "half height", hence the
     * 2 multiplier.
     */
    PolygonShape jumperShape = new PolygonShape();
    jumperShape.setAsBox(jumperSprite.getWidth() / (2 * PIXELS_PER_METER),
            jumperSprite.getHeight() / (2 * PIXELS_PER_METER));

    /**
     * The character should not ever spin around on impact.
     */
    jumper.setFixedRotation(true);

    /**
     * The density and friction of the jumper were found experimentally.
     * Play with the numbers and watch how the character moves faster or
     * slower.
     */
    FixtureDef jumperFixtureDef = new FixtureDef();
    jumperFixtureDef.shape = jumperShape;
    jumperFixtureDef.density = 1.0f;
    jumperFixtureDef.friction = 5.0f;

    jumper.createFixture(jumperFixtureDef);
    jumperShape.dispose();

    tiledMapHelper.loadCollisions("data/collisions.txt", world, PIXELS_PER_METER);

    debugRenderer = new Box2DDebugRenderer();

    lastRender = System.nanoTime();
}