Example usage for com.badlogic.gdx.physics.box2d Body getFixtureList

List of usage examples for com.badlogic.gdx.physics.box2d Body getFixtureList

Introduction

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

Prototype

public Array<Fixture> getFixtureList() 

Source Link

Document

Get the list of all fixtures attached to this body.

Usage

From source file:com.agateau.pixelwheels.utils.Box2DUtils.java

License:Open Source License

public static void setCollisionInfo(Body body, int categoryBits, int maskBits) {
    for (Fixture fixture : body.getFixtureList()) {
        Filter filter = fixture.getFilterData();
        filter.categoryBits = (short) categoryBits;
        filter.maskBits = (short) maskBits;
        fixture.setFilterData(filter);/*from w w  w.  j a  va2s.  co m*/
    }
}

From source file:com.agateau.pixelwheels.utils.Box2DUtils.java

License:Open Source License

public static void setBodyRestitution(Body body, float restitution) {
    for (Fixture fixture : body.getFixtureList()) {
        fixture.setRestitution(restitution);
    }//  w w w  .ja  v a2 s  .c  om
}

From source file:com.altportalgames.colorrain.utils.Box2DDebugRenderer.java

License:Apache License

private void renderBodies(World world) {
    for (Iterator<Body> iter = world.getBodies(); iter.hasNext();) {
        Body body = iter.next();
        Transform transform = body.getTransform();
        int len = body.getFixtureList().size();
        List<Fixture> fixtures = body.getFixtureList();
        for (int i = 0; i < len; i++) {
            Fixture fixture = fixtures.get(i);
            if (body.isActive() == false)
                drawShape(fixture, transform, SHAPE_NOT_ACTIVE);
            else if (body.getType() == BodyType.StaticBody)
                drawShape(fixture, transform, SHAPE_STATIC);
            else if (body.getType() == BodyType.KinematicBody)
                drawShape(fixture, transform, SHAPE_KINEMATIC);
            else if (body.isAwake() == false)
                drawShape(fixture, transform, SHAPE_NOT_AWAKE);
            else/*w w  w . j av  a2s  . com*/
                drawShape(fixture, transform, SHAPE_AWAKE);
        }
    }

    for (Iterator<Joint> iter = world.getJoints(); iter.hasNext();) {
        Joint joint = iter.next();
        drawJoint(joint);
    }

    int len = world.getContactList().size();
    for (int i = 0; i < len; i++)
        drawContact(world.getContactList().get(i));
}

From source file:com.blindtigergames.werescrewed.debug.SBox2DDebugRenderer.java

License:Apache License

protected void renderBody(Body body) {
    Transform transform = body.getTransform();
    int len = body.getFixtureList().size();
    List<Fixture> fixtures = body.getFixtureList();
    for (int i = 0; i < len; i++) {
        Fixture fixture = fixtures.get(i);

        if (drawBodies) {
            if (body.isActive() == false)
                drawShape(fixture, transform, SHAPE_NOT_ACTIVE);
            else if (body.getType() == BodyType.StaticBody)
                drawShape(fixture, transform, SHAPE_STATIC);
            else if (body.getType() == BodyType.KinematicBody)
                drawShape(fixture, transform, SHAPE_KINEMATIC);
            else if (body.isAwake() == false)
                drawShape(fixture, transform, SHAPE_NOT_AWAKE);
            else/*from w  w  w . ja  v  a 2 s  .  c  o m*/
                drawShape(fixture, transform, SHAPE_AWAKE);

            if (drawVelocities) {
                Vector2 position = body.getPosition();
                drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR);
            }
        }

        if (drawAABBs) {
            drawAABB(fixture, transform);
        }
    }
}

From source file:com.me.mygdxgame.Entities.MydebugRenderer.java

License:Apache License

protected void renderBody(Body body) {
    Transform transform = body.getTransform();
    for (Fixture fixture : body.getFixtureList()) {
        if (drawBodies) {
            drawShape(fixture, transform, getColorByBody(body));
            if (drawVelocities) {
                Vector2 position = body.getPosition();
                drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR);
            }//  w w  w  . ja  va  2s .  c om
        }

        if (drawAABBs) {
            drawAABB(fixture, transform);
        }
    }
}

From source file:com.pastew.autogearbox.handlers.Box2DSprite.java

License:Apache License

/** draws all the {@link Box2DSprite Box2DSprites} on the {@link Body} or {@link Fixture} that hold them in their user data in the given {@link World} */
public static void draw(Batch batch, World world, boolean sortByZ) {
    @SuppressWarnings("unchecked")
    Array<Body> tmpBodies = Pools.obtain(Array.class);
    world.getBodies(tmpBodies);/*w w  w.  j a  v  a2  s  .  c o m*/

    if (sortByZ) {
        @SuppressWarnings("unchecked")
        ObjectMap<Box2DSprite, Object> tmpZMap = Pools.obtain(ObjectMap.class);
        tmpZMap.clear();
        for (Body body : tmpBodies) {
            Box2DSprite tmpBox2DSprite;
            if ((tmpBox2DSprite = userDataAccessor.apply(body.getUserData())) != null)
                tmpZMap.put(tmpBox2DSprite, body);
            for (Fixture fixture : body.getFixtureList())
                if ((tmpBox2DSprite = userDataAccessor.apply(fixture.getUserData())) != null)
                    tmpZMap.put(tmpBox2DSprite, fixture);
        }

        @SuppressWarnings("unchecked")
        Array<Box2DSprite> tmpKeys = Pools.obtain(Array.class);
        Iterator<Box2DSprite> keys = tmpZMap.keys();
        while (keys.hasNext())
            tmpKeys.add(keys.next());
        tmpKeys.sort(zComparator);
        for (Box2DSprite key : tmpKeys) {
            Object value = tmpZMap.get(key);
            if (value instanceof Body)
                key.draw(batch, (Body) value);
            else
                key.draw(batch, (Fixture) value);
        }

        tmpKeys.clear();
        tmpZMap.clear();
        Pools.free(tmpKeys);
        Pools.free(tmpZMap);
    } else
        for (Body body : tmpBodies) {
            Box2DSprite tmpBox2DSprite;
            if ((tmpBox2DSprite = userDataAccessor.apply(body.getUserData())) != null)
                tmpBox2DSprite.draw(batch, body);
            for (Fixture fixture : body.getFixtureList())
                if ((tmpBox2DSprite = userDataAccessor.apply(fixture.getUserData())) != null)
                    tmpBox2DSprite.draw(batch, fixture);
        }

    tmpBodies.clear();
    Pools.free(tmpBodies);
}

From source file:com.redtoorange.game.states.MissionState.java

License:Open Source License

/** Build all the walls for the game map based on the TMX's files objects layer. */
private void initWalls() {
    for (Rectangle r : gameMap.walls) {
        Filter w = new Filter();
        w.groupIndex = Global.WALL;//from  w w w .j  a  v  a2s.c  o m
        w.maskBits = Global.ENEMY | Global.PLAYER | Global.LIGHT | Global.BULLET_LIVE;

        Body b = Box2DFactory.createStaticBody(physicsSystem, r);
        b.getFixtureList().first().setFilterData(w);
        b.setUserData(r);
    }
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @return the vertices of all fixtures of a body */
public static Vector2[][] fixtureVertices(Body body) {
    Array<Fixture> fixtures = body.getFixtureList();
    Vector2[][] vertices = new Vector2[fixtures.size][];
    for (int i = 0; i < vertices.length; i++)
        vertices[i] = vertices(fixtures.get(i));
    return vertices;
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @return the minimal x value of the vertices of all fixtures of the the given Body */
public static float minX(Body body) {
    float x = Float.POSITIVE_INFINITY, tmp;
    for (Fixture fixture : body.getFixtureList())
        if ((tmp = minX(fixture)) < x)
            x = tmp;//from  w  w  w  .  j  av a2  s .  c  o  m
    return x;
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java

License:Apache License

/** @return the minimal y value of the vertices of all fixtures of the the given Body */
public static float minY(Body body) {
    float y = Float.POSITIVE_INFINITY, tmp;
    for (Fixture fixture : body.getFixtureList())
        if ((tmp = minY(fixture)) < y)
            y = tmp;/*from  w  w  w.  ja  v  a2s  .c om*/
    return y;
}