Example usage for com.badlogic.gdx.physics.box2d Fixture setUserData

List of usage examples for com.badlogic.gdx.physics.box2d Fixture setUserData

Introduction

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

Prototype

public void setUserData(Object userData) 

Source Link

Document

Sets custom user data.

Usage

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

License:Apache License

/** creates a {@link Fixture} from a {@link MapObject}
 *  @param mapObject the {@link MapObject} to parse
 *  @param body the {@link Body} to create the {@link Fixture Fixtures} on
 *  @return the parsed {@link Fixture} */
public Fixture createFixture(MapObject mapObject, Body body) {
    if ((mapObject = listener.createFixture(mapObject)) == null)
        return null;

    String orientation = findProperty(aliases.orientation, aliases.orthogonal, heritage, mapProperties,
            layerProperties, mapObject.getProperties());
    transform(mat4, orientation);//from w  ww .  java 2  s  . co  m

    Shape shape = null;
    if (mapObject instanceof RectangleMapObject) {
        Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();
        vec3.set(rectangle.x, rectangle.y, 0);
        vec3.mul(mat4);
        float x = vec3.x, y = vec3.y, width, height;
        if (!orientation.equals(aliases.staggered)) {
            vec3.set(rectangle.width, rectangle.height, 0).mul(mat4);
            width = vec3.x;
            height = vec3.y;
        } else {
            width = rectangle.width * unitScale;
            height = rectangle.height * unitScale;
        }
        ((PolygonShape) (shape = new PolygonShape())).setAsBox(width / 2, height / 2,
                vec2.set(x - body.getPosition().x + width / 2, y - body.getPosition().y + height / 2),
                body.getAngle());
    } else if (mapObject instanceof PolygonMapObject || mapObject instanceof PolylineMapObject) {
        FloatArray vertices = Pools.obtain(FloatArray.class);
        vertices.clear();
        vertices.addAll(mapObject instanceof PolygonMapObject
                ? ((PolygonMapObject) mapObject).getPolygon().getTransformedVertices()
                : ((PolylineMapObject) mapObject).getPolyline().getTransformedVertices());
        for (int ix = 0, iy = 1; iy < vertices.size; ix += 2, iy += 2) {
            vec3.set(vertices.get(ix), vertices.get(iy), 0);
            vec3.mul(mat4);
            vertices.set(ix, vec3.x - body.getPosition().x);
            vertices.set(iy, vec3.y - body.getPosition().y);
        }
        if (mapObject instanceof PolygonMapObject)
            ((PolygonShape) (shape = new PolygonShape())).set(vertices.items, 0, vertices.size);
        else if (vertices.size == 4)
            ((EdgeShape) (shape = new EdgeShape())).set(vertices.get(0), vertices.get(1), vertices.get(2),
                    vertices.get(3));
        else {
            vertices.shrink();
            ((ChainShape) (shape = new ChainShape())).createChain(vertices.items);
        }
        Pools.free(vertices);
    } else if (mapObject instanceof CircleMapObject || mapObject instanceof EllipseMapObject) {
        if (mapObject instanceof CircleMapObject) {
            Circle circle = ((CircleMapObject) mapObject).getCircle();
            vec3.set(circle.x, circle.y, circle.radius);
        } else {
            Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
            if (ellipse.width != ellipse.height)
                throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because "
                        + ClassReflection.getSimpleName(mapObject.getClass())
                        + "s that are not circles are not supported");
            vec3.set(ellipse.x + ellipse.width / 2, ellipse.y + ellipse.height / 2, ellipse.width / 2);
        }
        vec3.mul(mat4);
        vec3.sub(body.getPosition().x, body.getPosition().y, 0);
        CircleShape circleShape = (CircleShape) (shape = new CircleShape());
        circleShape.setPosition(vec2.set(vec3.x, vec3.y));
        circleShape.setRadius(vec3.z);
    } else if (mapObject instanceof TextureMapObject)
        throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because "
                + ClassReflection.getSimpleName(mapObject.getClass()) + "s are not supported");
    else
        assert false : mapObject + " is a not known subclass of " + MapObject.class.getName();

    MapProperties properties = mapObject.getProperties();

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    assignProperties(fixtureDef, heritage);
    assignProperties(fixtureDef, mapProperties);
    assignProperties(fixtureDef, layerProperties);
    assignProperties(fixtureDef, properties);

    Fixture fixture = body.createFixture(fixtureDef);
    fixture.setUserData(findProperty(aliases.userData, fixture.getUserData(), heritage, mapProperties,
            layerProperties, properties));

    shape.dispose();

    fixtures.put(findAvailableName(mapObject.getName(), fixtures), fixture);
    listener.created(fixture, mapObject);

    return fixture;
}

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

License:Apache License

/** clones a {@link Fixture}
 *  @param fixture the {@link Fixture} to copy
 *  @param body the {@link Body} to create a copy of the given {@code fixture} on
 *  @param shape if the {@link Fixture#getShape() shape} of the given {@code fixture} should be deep {@link #clone(Shape) copied} as well
 *  @return the copied {@link Fixture} */
public static Fixture clone(Fixture fixture, Body body, boolean shape) {
    FixtureDef fixtureDef = createDef(fixture);
    if (shape)//  ww w . j  ava  2s. c  o  m
        fixtureDef.shape = clone(fixture.getShape());
    Fixture clone = body.createFixture(fixtureDef);
    clone.setUserData(clone.getUserData());
    return clone;
}

From source file:com.strategames.engine.utils.BodyEditorLoader.java

License:Open Source License

/**
 * Creates and applies the fixtures defined in the editor. The name
 * parameter is used to retrieve the right fixture from the loaded file.
 * <br/><br/>//ww w .ja va2 s  .co m
 *
 * The body reference point (the red cross in the tool) is by default
 * located at the bottom left corner of the image. This reference point
 * will be put right over the BodyDef position point. Therefore, you should
 * place this reference point carefully to let you place your body in your
 * world easily with its BodyDef.position point. Note that to draw an image
 * at the position of your body, you will need to know this reference point
 * (see {@link #getOrigin(java.lang.String, float)}.
 * <br/><br/>
 *
 * Also, saved shapes are normalized. As shown in the tool, the width of
 * the image is considered to be always 1 meter. Thus, you need to provide
 * a scale factor so the polygons get resized according to your needs (not
 * every body is 1 meter large in your game, I guess).
 *
 * @param body The Box2d body you want to attach the fixture to.
 * @param name The name of the fixture you want to loadSync.
 * @param uniqueIdentifier will be added to the fixture. Retrieve using fixture.getUserData()
 * @param fd The fixture parameters to apply to the created body fixture.
 */
public void attachFixture(Body body, String name, int uniqueIdentifier, FixtureDef fd) throws RuntimeException {
    RigidBodyModel rbModel = model.rigidBodies.get(name);
    if (rbModel == null)
        throw new RuntimeException("Name '" + name + "' was not found.");

    for (int i = 0, n = rbModel.polygons.size(); i < n; i++) {
        PolygonModel polygon = rbModel.polygons.get(i);
        polygonShape.set(polygon.buffer);
        fd.shape = polygonShape;
        Fixture fixture = body.createFixture(fd); // Added to support breakable objects
        fixture.setUserData(new Integer(uniqueIdentifier)); // Added to support breakable objects
    }

    for (int i = 0, n = rbModel.circles.size(); i < n; i++) {
        CircleModel circle = rbModel.circles.get(i);

        circleShape.setPosition(circle.centerBuffer);
        circleShape.setRadius(circle.radiusBuffer);
        fd.shape = circleShape;
        Fixture fixture = body.createFixture(fd); // Added to support breakable objects
        fixture.setUserData(new Integer(uniqueIdentifier)); // Added to support breakable objects
    }
}

From source file:de.fhkoeln.game.utils.Box2DMapObjectParser.java

License:Apache License

/** creates a {@link com.badlogic.gdx.physics.box2d.Fixture} from a {@link com.badlogic.gdx.maps.MapObject}
 *  @param mapObject the {@link com.badlogic.gdx.maps.MapObject} to parse
 *  @param body the {@link com.badlogic.gdx.physics.box2d.Body} to create the {@link com.badlogic.gdx.physics.box2d.Fixture Fixtures} on
 *  @return the parsed {@link com.badlogic.gdx.physics.box2d.Fixture} */
public Fixture createFixture(MapObject mapObject, Body body) {
    if ((mapObject = listener.createFixture(mapObject)) == null)
        return null;

    String orientation = findProperty(aliases.orientation, aliases.orthogonal, heritage, mapProperties,
            layerProperties, mapObject.getProperties());
    transform(mat4, orientation);//ww w  . j  ava 2s.  c  o  m

    Shape shape = null;
    if (mapObject instanceof RectangleMapObject) {
        Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();
        vec3.set(rectangle.x, rectangle.y, 0);
        vec3.mul(mat4);
        float x = vec3.x, y = vec3.y, width, height;
        if (!orientation.equals(aliases.staggered)) {
            vec3.set(rectangle.width, rectangle.height, 0).mul(mat4);
            width = vec3.x;
            height = vec3.y;
        } else {
            width = rectangle.width * unitScale;
            height = rectangle.height * unitScale;
        }
        ((PolygonShape) (shape = new PolygonShape())).setAsBox(width / 2, height / 2,
                vec2.set(x - body.getPosition().x + width / 2, y - body.getPosition().y + height / 2),
                body.getAngle());
    } else if (mapObject instanceof PolygonMapObject || mapObject instanceof PolylineMapObject) {
        FloatArray vertices = Pools.obtain(FloatArray.class);
        vertices.clear();
        vertices.addAll(mapObject instanceof PolygonMapObject
                ? ((PolygonMapObject) mapObject).getPolygon().getTransformedVertices()
                : ((PolylineMapObject) mapObject).getPolyline().getTransformedVertices());
        for (int ix = 0, iy = 1; iy < vertices.size; ix += 2, iy += 2) {
            vec3.set(vertices.get(ix), vertices.get(iy), 0);
            vec3.mul(mat4);
            vertices.set(ix, vec3.x - body.getPosition().x);
            vertices.set(iy, vec3.y - body.getPosition().y);
        }
        if (mapObject instanceof PolygonMapObject)
            ((PolygonShape) (shape = new PolygonShape())).set(vertices.items, 0, vertices.size);
        else if (vertices.size == 4)
            ((EdgeShape) (shape = new EdgeShape())).set(vertices.get(0), vertices.get(1), vertices.get(2),
                    vertices.get(3));
        else {
            vertices.shrink();
            ((ChainShape) (shape = new ChainShape())).createChain(vertices.items);
        }
        Pools.free(vertices);
    } else if (mapObject instanceof CircleMapObject || mapObject instanceof EllipseMapObject) {
        if (mapObject instanceof CircleMapObject) {
            Circle circle = ((CircleMapObject) mapObject).getCircle();
            vec3.set(circle.x, circle.y, circle.radius);
        } else {
            Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
            if (ellipse.width != ellipse.height)
                throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because "
                        + mapObject.getClass().getSimpleName() + "s that are not circles are not supported");
            vec3.set(ellipse.x + ellipse.width / 2, ellipse.y + ellipse.height / 2, ellipse.width / 2);
        }
        vec3.mul(mat4);
        vec3.sub(body.getPosition().x, body.getPosition().y, 0);
        CircleShape circleShape = (CircleShape) (shape = new CircleShape());
        circleShape.setPosition(vec2.set(vec3.x, vec3.y));
        circleShape.setRadius(vec3.z);
    } else if (mapObject instanceof TextureMapObject)
        throw new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because "
                + mapObject.getClass().getSimpleName() + "s are not supported");
    else
        assert false : mapObject + " is a not known subclass of " + MapObject.class.getName();

    MapProperties properties = mapObject.getProperties();

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    assignProperties(fixtureDef, heritage);
    assignProperties(fixtureDef, mapProperties);
    assignProperties(fixtureDef, layerProperties);
    assignProperties(fixtureDef, properties);

    Fixture fixture = body.createFixture(fixtureDef);
    fixture.setUserData(findProperty(aliases.userData, fixture.getUserData(), heritage, mapProperties,
            layerProperties, properties));

    shape.dispose();

    fixtures.put(findAvailableName(mapObject.getName(), fixtures), fixture);
    listener.created(fixture, mapObject);

    return fixture;
}

From source file:genuini.world.ContactHandler.java

@Override
public void beginContact(Contact contact) {
    Fixture fa = contact.getFixtureA();
    Fixture fb = contact.getFixtureB();/* w w w .  ja  va  2 s .c  om*/

    if (fa == null || fb == null)
        return;

    if (fa.getUserData() != null && fa.getUserData().equals("foot")) {
        numFootContacts++;
    }

    if (fb.getUserData() != null && fb.getUserData().equals("foot")) {
        numFootContacts++;
    }

    if ((fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null
            && fb.getUserData().equals("spring"))
            || (fa.getUserData() != null && fa.getUserData().equals("spring") && fb.getUserData() != null
                    && fb.getUserData().equals("foot"))) {
        bounce = true;
    }

    if ((fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null
            && fb.getUserData().equals("button"))
            || (fa.getUserData() != null && fa.getUserData().equals("button") && fb.getUserData() != null
                    && fb.getUserData().equals("foot"))) {
        button = true;
    }

    if (fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null
            && fb.getUserData().equals("spike")
            || fa.getUserData() != null && fa.getUserData().equals("spike") && fb.getUserData() != null
                    && fb.getUserData().equals("foot")) {
        bounce = true;
        dangerous = true;
        playerHurt();
    }

    if (fa.getUserData() != null && fa.getUserData().equals("fireball")) {
        if (fb.getUserData() != null && fb.getUserData().equals("player")) {
            dangerous = true;
            playerHurt();
        }
    }

    if (fb.getUserData() != null && fb.getUserData().equals("fireball")) {
        if (fa.getUserData() != null && fa.getUserData().equals("player")) {
            dangerous = true;
            playerHurt();
        }
    }

    if (fa.getUserData() != null && (fa.getUserData().equals("slime") || fa.getUserData().equals("snail"))) {
        if (fb.getUserData() != null && fb.getUserData().equals("player")) {
            dangerous = true;
            fb.getBody().applyLinearImpulse(0, 8f, 0, 0, true);
            playerHurt();
        }
    }

    if (fb.getUserData() != null && (fb.getUserData().equals("slime") || fb.getUserData().equals("snail"))) {
        if (fa.getUserData() != null && fa.getUserData().equals("player")) {
            dangerous = true;
            fa.getBody().applyLinearImpulse(0, 8f, 0, 0, true);
            playerHurt();
        }
    }

    if ((fa.getUserData() != null && fa.getUserData().equals("victory"))
            || (fb.getUserData() != null && fb.getUserData().equals("victory"))) {
        victory = true;
    }

    if (fa.getUserData() != null && fa.getUserData().equals("questionBox")) {
        fa.setUserData("questionBoxDisabled");
    } else if (fb.getUserData() != null && fb.getUserData().equals("questionBox")) {
        fb.setUserData("questionBoxDisabled");
    }

}

From source file:genuini.world.ContactHandler.java

@Override
public void endContact(Contact contact) {
    Fixture fa = contact.getFixtureA();/*from  www  .  j a v  a2 s . c om*/
    Fixture fb = contact.getFixtureB();

    if (fa == null || fb == null)
        return;

    if (fa.getUserData() != null && fa.getUserData().equals("foot")) {
        numFootContacts--;
    }
    if (fb.getUserData() != null && fb.getUserData().equals("foot")) {
        numFootContacts--;
    }

    if (fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null
            && fb.getUserData().equals("spring")
            || fa.getUserData() != null && fa.getUserData().equals("spring") && fb.getUserData() != null
                    && fb.getUserData().equals("foot")) {
        bounce = false;
    }

    if ((fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null
            && fb.getUserData().equals("button"))
            || (fa.getUserData() != null && fa.getUserData().equals("button") && fb.getUserData() != null
                    && fb.getUserData().equals("foot"))) {
        button = false;
    }

    if (fa.getUserData() != null && fa.getUserData().equals("foot") && fb.getUserData() != null
            && fb.getUserData().equals("spike")
            || fa.getUserData() != null && fa.getUserData().equals("spike") && fb.getUserData() != null
                    && fb.getUserData().equals("foot")) {
        bounce = false;
        dangerous = false;
    }

    if (fa.getUserData() != null && fa.getUserData().equals("fireball")) {
        if (fb.getUserData() != null && fb.getUserData().equals("player")) {
            dangerous = false;
        }
        if (fb.getUserData() != null
                && (fb.getUserData().equals("slime") || fb.getUserData().equals("snail"))) {
            fb.setUserData("setToDestroy");
        }
        fa.setUserData("toDestroy");
    }

    if (fb.getUserData() != null && fb.getUserData().equals("fireball")) {
        if (fa.getUserData() != null && fa.getUserData().equals("player")) {
            dangerous = false;
        }
        if (fa.getUserData() != null
                && (fa.getUserData().equals("slime") || fa.getUserData().equals("snail"))) {
            fa.setUserData("setToDestroy");
        }
        fb.setUserData("toDestroy");
    }

    if (fa.getUserData() != null && fa.getUserData().equals("slime")) {
        if (fb.getUserData() != null && fb.getUserData().equals("player")) {
            dangerous = false;
            fa.setUserData("setToDestroy");
        }
    }

    if (fb.getUserData() != null && fb.getUserData().equals("slime")) {
        if (fa.getUserData() != null && fa.getUserData().equals("player")) {
            dangerous = false;
            fb.setUserData("setToDestroy");
        }
    }

}

From source file:headmade.arttag.Guard.java

License:Apache License

public void createBody(ArtTagScreen artTagScreen, float x, float y) {
    Gdx.app.log(TAG, "Creating Guard body at " + x + ", " + y);
    { // body/*  w  w w .  j ava2  s . co  m*/
        final CircleShape circle = new CircleShape();
        circle.setRadius(BODY_RADIUS);

        final BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.fixedRotation = true;
        bd.position.set(x, y);
        final FixtureDef fd = new FixtureDef();
        fd.shape = circle;
        fd.restitution = 1.5f;
        fd.friction = 0.0f;
        fd.filter.categoryBits = ArtTag.CAT_GUARD;
        fd.filter.maskBits = ArtTag.MASK_GUARD;

        body = artTagScreen.world.createBody(bd);
        final Fixture fix = body.createFixture(fd);

        final Sprite t = Assets.instance.skin.getSprite(AssetTextures.guard);
        final Box2DSprite playerSprite = new Box2DSprite(t);
        fix.setUserData(playerSprite);
        body.setUserData(this);

        circle.dispose();
    }

    { // vision cone
        final float playerLightConeLength = lightLength * LIGHT_CONE_LENGTH_FACTOR;
        final float coneHalfWidth = MathUtils.sinDeg(lightAngle) * playerLightConeLength;

        final PolygonShape shape = new PolygonShape();
        final Vector2[] vertices = { new Vector2(0, BODY_RADIUS * 0.9f),
                new Vector2(coneHalfWidth, playerLightConeLength), new Vector2(0, playerLightConeLength * 1.2f),
                new Vector2(-coneHalfWidth, playerLightConeLength) };
        shape.set(vertices);

        final BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.fixedRotation = true;
        bd.position.set(x, y);

        final FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.isSensor = true;
        fd.filter.categoryBits = ArtTag.CAT_GUARDLIGHT;
        fd.filter.maskBits = ArtTag.MASK_GUARDLIGHT;

        final Fixture fix = body.createFixture(fd);
        fix.setUserData(this);

        shape.dispose();
    }

    { // player Flashlight
        light = new ConeLight(artTagScreen.rayHandler, ArtTag.gameSettings.rays, null, lightLength, 0, 0, 0f,
                lightAngle);//
        light.attachToBody(body, 0f, 0f, 90);
        light.setIgnoreAttachedBody(true);
        light.setSoftnessLength(0.5f);
        light.setColor(1f, 0.9f, 0.7f, 1f);
        light.setContactFilter(ArtTag.CAT_LIGHT, ArtTag.GROUP_LIGHT, ArtTag.MASK_LIGHT);
        artTagScreen.lights.add(light);

        // LASER!
        // playerLight = new ConeLight(artTagScreen.rayHandler, 3, null, 10f, 0, 0, 0f, 2f);//
        // // MathUtils.random(30f, 50f));
        // playerLight.attachToBody(body, 0f, 0f, 90);
        // playerLight.setIgnoreAttachedBody(true);
        // playerLight.setSoftnessLength(1f);
        // playerLight.setColor(1f, 0.0f, 0.0f, 1f);
        // playerLight.setContactFilter(ArtTag.CAT_LIGHT, ArtTag.GROUP_LIGHT, ArtTag.MASK_LIGHT);
        // artTagScreen.lights.add(playerLight);

    }
}

From source file:headmade.arttag.Player.java

License:Apache License

public void createBody(ArtTagScreen artTagScreen, float x, float y) {
    Gdx.app.log(TAG, "Creating player at " + x + ", " + y);
    { // body/*w  ww.j ava2s.  c  o  m*/
        final CircleShape circle = new CircleShape();
        circle.setRadius(PLAYER_RADIUS);

        final BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.fixedRotation = true;
        bd.position.set(x, y);
        final FixtureDef fd = new FixtureDef();
        fd.shape = circle;
        fd.filter.categoryBits = ArtTag.CAT_PLAYER;
        fd.filter.maskBits = ArtTag.MASK_PLAYER;

        body = artTagScreen.world.createBody(bd);
        final Fixture fix = body.createFixture(fd);

        final TextureRegion t = Assets.instance.skin.getRegion(AssetTextures.player);
        final Box2DSprite playerSprite = new Box2DSprite(t);
        fix.setUserData(playerSprite);
        // body.setUserData(playerSprite);

        circle.dispose();
    }

    { // Player vision cone
        final float playerLightConeLength = playerLightLength * PLAYERLIGHT_CONE_LENGTH_FACTOR;
        final float coneHalfWidth = MathUtils.sinDeg(playerlightAngle) * playerLightConeLength;

        final PolygonShape shape = new PolygonShape();
        final Vector2[] vertices = { new Vector2(0, PLAYER_RADIUS * 0.9f),
                new Vector2(coneHalfWidth, playerLightConeLength), new Vector2(0, playerLightConeLength * 1.2f),
                new Vector2(-coneHalfWidth, playerLightConeLength) };
        shape.set(vertices);

        final BodyDef bd = new BodyDef();
        bd.type = BodyType.DynamicBody;
        bd.fixedRotation = true;
        bd.position.set(x, y);

        final FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.isSensor = true;
        fd.filter.categoryBits = ArtTag.CAT_PLAYERLIGHT;
        fd.filter.maskBits = ArtTag.MASK_PLAYERLIGHT;

        final Fixture fix = body.createFixture(fd);

        shape.dispose();
    }

    { // player Flashlight
        playerLight = new ConeLight(artTagScreen.rayHandler, ArtTag.gameSettings.rays, null, playerLightLength,
                0, 0, 0f, playerlightAngle);//
        playerLight.attachToBody(body, 0f, 0f, 90);
        playerLight.setIgnoreAttachedBody(true);
        playerLight.setSoftnessLength(0.5f);
        playerLight.setColor(1f, 0.9f, 0.7f, 1f);
        playerLight.setContactFilter(ArtTag.CAT_LIGHT, ArtTag.GROUP_LIGHT, ArtTag.MASK_LIGHT);
        artTagScreen.lights.add(playerLight);

        // LASER!
        // playerLight = new ConeLight(artTagScreen.rayHandler, 3, null, 10f, 0, 0, 0f, 2f);//
        // // MathUtils.random(30f, 50f));
        // playerLight.attachToBody(body, 0f, 0f, 90);
        // playerLight.setIgnoreAttachedBody(true);
        // playerLight.setSoftnessLength(1f);
        // playerLight.setColor(1f, 0.0f, 0.0f, 1f);
        // playerLight.setContactFilter(ArtTag.CAT_LIGHT, ArtTag.GROUP_LIGHT, ArtTag.MASK_LIGHT);
        // artTagScreen.lights.add(playerLight);

        // PointLight
        // final PointLight light2 = new PointLight(artTagScreen.rayHandler, ArtTag.RAYS_NUM);
        // light2.setPosition(body.getWorldCenter());
        // light2.setDistance(0.5f);
        // light2.attachToBody(body, 0f, 0f);
        // light2.setColor(0.8f, 0.8f, 1f, 0.5f);
        // light2.setSoftnessLength(0.5f);
        // artTagScreen.lights.add(light2);
    }
}

From source file:io.piotrjastrzebski.sfg.game.objects.obstacles.ScoreSensor.java

License:Open Source License

public ScoreSensor(Obstacle obstacle) {
    world = Locator.getWorld();//  w  w w.ja  va  2  s  .  c  o m
    this.parent = obstacle;

    final BodyDef obstacleBodyDef = new BodyDef();
    obstacleBodyDef.type = BodyType.StaticBody;
    obstacleBodyDef.position.set(0, 2);
    sensorBody = world.createBody(obstacleBodyDef);

    final PolygonShape rect = new PolygonShape();
    rect.setAsBox(0.5f, GameScreen.VIEWPORT_HEIGHT / 2.0f);

    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = rect;
    fixtureDef.isSensor = true; // wont collide
    fixtureDef.filter.categoryBits = Collision.SENSOR;
    fixtureDef.filter.maskBits = Collision.MASK_SENSOR;

    final Fixture f = sensorBody.createFixture(fixtureDef);
    f.setUserData(SensorType.SCORE);
    sensorBody.setUserData(this);

    // Clean up
    rect.dispose();
}

From source file:loon.physics.PhysicsBodyBuilder.java

License:Apache License

public Body build(boolean disposeShapes) {
    Body body = world.createBody(bodyDef);

    for (int i = 0; i < fixtureDefs.size(); i++) {
        FixtureDef fixtureDef = fixtureDefs.get(i);
        Fixture fixture = body.createFixture(fixtureDef);
        fixture.setUserData(fixtureUserDatas.get(i));
    }// w w  w. j  a va 2 s  . c o  m

    if (massSet) {
        MassData bodyMassData = body.getMassData();
        massData.center.set(bodyMassData.center);
        body.setMassData(massData);
    }

    body.setUserData(userData);
    body.setTransform(position, angle);

    reset(disposeShapes);
    return body;
}