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

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

Introduction

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

Prototype

public boolean isActive() 

Source Link

Document

Get the active state of the body.

Usage

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/*  ww w.j a  va 2 s  .c  om*/
                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

private void renderBodies(World world) {
    renderer.begin(ShapeType.Line);

    if (drawBodies || drawAABBs) {
        for (Iterator<Body> iter = world.getBodies(); iter.hasNext();) {
            Body body = iter.next();
            if (body.isActive() || drawInactiveBodies)
                renderBody(body);/*w  ww .  j a va2  s  .co  m*/
        }
    }

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

    if (Gdx.gl10 != null)
        Gdx.gl10.glPointSize(3);
    renderer.begin(ShapeType.Point);
    int len = world.getContactList().size();
    for (int i = 0; i < len; i++)
        drawContact(world.getContactList().get(i));
    renderer.end();
    if (Gdx.gl10 != null)
        Gdx.gl10.glPointSize(1);
}

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// ww  w.  j  a  va  2s.  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.dongbat.game.util.PhysicsUtil.java

/**
 * Set radius for an entity//from w  w w  .ja va  2 s .c o m
 *
 * @param world artemis world
 * @param e entity that you want to set radius
 * @param r radius that you want to set for entity
 */
public static void setRadius(com.artemis.World world, Entity e, float r) {
    Body body = PhysicsUtil.getBody(world, e);
    if (!body.isActive()) {
        return;
    }
    getBody(world, e).getFixtureList().get(0).getShape().setRadius(r);
}

From source file:com.mcprog.ragnar.screens.GameScreen.java

License:Apache License

/**
 * Safely destroys arrow that have been added to an array of bodies to remove
 * These are arrows that have either hit each other, the player, or the outside bounds
 * <li>1. sets the bodies inactive</li>
 * <li>2. destroys the inactive bodies</li>
 * This means that it takes 2 frames to completely delete the bodies
 *//*w ww . ja va 2s.  c  o m*/
private void safelyDestroyBodies() {
    world.getBodies(bodies);
    if (!world.isLocked()) {
        for (Body b : bodiesToDelete) {
            b.setActive(false);
        }
        bodiesToDelete.clear();
        for (Body i : bodies) {
            if (!i.isActive()) {
                world.destroyBody(i);
            }
        }
    }
}

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

License:Apache License

private void renderBodies(World world) {
    renderer.begin(ShapeType.Line);

    if (drawBodies || drawAABBs) {
        world.getBodies(bodies);//from  w w w .  j ava  2  s.  com
        for (Iterator<Body> iter = bodies.iterator(); iter.hasNext();) {
            Body body = iter.next();
            if (body.isActive() || drawInactiveBodies)
                renderBody(body);
        }
    }

    if (drawJoints) {
        world.getJoints(joints);
        for (Iterator<Joint> iter = joints.iterator(); iter.hasNext();) {
            Joint joint = iter.next();
            drawJoint(joint);
        }
    }
    renderer.end();
    if (drawContacts) {
        if (Gdx.gl10 != null)
            Gdx.gl10.glPointSize(3);
        renderer.begin(ShapeType.Point);
        for (Contact contact : world.getContactList())
            drawContact(contact);
        renderer.end();
        if (Gdx.gl10 != null)
            Gdx.gl10.glPointSize(1);
    }
}

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

License:Apache License

private Color getColorByBody(Body body) {
    if (body.isActive() == false)
        return SHAPE_NOT_ACTIVE;
    else if (body.getType() == BodyType.StaticBody)
        return SHAPE_STATIC;
    else if (body.getType() == BodyType.KinematicBody)
        return SHAPE_KINEMATIC;
    else if (body.isAwake() == false)
        return SHAPE_NOT_AWAKE;
    else/*w ww  . j  a va  2s .co  m*/
        return SHAPE_AWAKE;
}

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

License:Apache License

/** @param body the body for which to setup a new {@link BodyDef}
 *  @return a new {@link BodyDef} instance that can be used to clone the given body */
public static BodyDef createDef(Body body) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.active = body.isActive();
    bodyDef.allowSleep = body.isSleepingAllowed();
    bodyDef.angle = body.getAngle();/*  ww  w  .ja v  a2s. c  om*/
    bodyDef.angularDamping = body.getAngularDamping();
    bodyDef.angularVelocity = body.getAngularVelocity();
    bodyDef.awake = body.isAwake();
    bodyDef.bullet = body.isBullet();
    bodyDef.fixedRotation = body.isFixedRotation();
    bodyDef.gravityScale = body.getGravityScale();
    bodyDef.linearDamping = body.getLinearDamping();
    bodyDef.linearVelocity.set(body.getLinearVelocity());
    bodyDef.position.set(body.getPosition());
    bodyDef.type = body.getType();
    return bodyDef;
}

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

License:Apache License

/** creates a deep copy of a {@link Body}
 *  @param body the {@link Body} to copy
 *  @param shapes if the {@link Shape Shapes} of the {@link Fixture Fixures} of the given {@code body} should be {@link #copy(Shape) copied} as well
 *  @return a deep copy of the given {@code body} */
public static Body copy(Body body, boolean shapes) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.active = body.isActive();
    bodyDef.allowSleep = body.isSleepingAllowed();
    bodyDef.angle = body.getAngle();/*from  w w  w .j a  v a 2s . com*/
    bodyDef.angularDamping = body.getAngularDamping();
    bodyDef.angularVelocity = body.getAngularVelocity();
    bodyDef.awake = body.isAwake();
    bodyDef.bullet = body.isBullet();
    bodyDef.fixedRotation = body.isFixedRotation();
    bodyDef.gravityScale = body.getGravityScale();
    bodyDef.linearDamping = body.getLinearDamping();
    bodyDef.linearVelocity.set(body.getLinearVelocity());
    bodyDef.position.set(body.getPosition());
    bodyDef.type = body.getType();
    Body copy = body.getWorld().createBody(bodyDef);
    copy.setUserData(body.getUserData());
    for (Fixture fixture : body.getFixtureList())
        copy(fixture, copy, shapes);
    return copy;
}

From source file:org.ams.physics.things.def.DefParser.java

License:Open Source License

public static void thingWithBodyToDefinition(ThingWithBody thingWithBody, ThingWithBodyDef def) {
    Body body = thingWithBody.getBody();
    Fixture firstFixture = body.getFixtureList().first();

    thingToDefinition(thingWithBody, def);

    def.active = body.isActive();
    def.angle = body.getAngle();//w ww  .ja  v a2s.c  om
    def.angularDamping = body.getAngularDamping();
    def.antiCollisionGroup = thingWithBody.getAntiCollisionGroup();
    def.awake = body.isAwake();
    def.bullet = body.isBullet();
    def.categoryBits = firstFixture.getFilterData().categoryBits;
    def.density = firstFixture.getDensity();
    def.fixedRotation = body.isFixedRotation();
    def.friction = firstFixture.getFriction();
    def.groupIndex = firstFixture.getFilterData().groupIndex;
    def.linearDamping = body.getLinearDamping();
    def.maskBits = firstFixture.getFilterData().maskBits;
    def.position.set(body.getPosition());
    def.restitution = firstFixture.getRestitution();
    def.type = body.getType();

}