Java 类com.badlogic.gdx.physics.box2d.CircleShape 实例源码

项目:homescreenarcade    文件:Box2DFactory.java   
/** Creates a circle object with the given position and radius. Resitution defaults to 0.6. */
public static Body createCircle(World world, float x, float y, float radius, boolean isStatic) {
    CircleShape sd = new CircleShape();
    sd.setRadius(radius);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = sd;
    fdef.density = 1.0f;
    fdef.friction = 0.3f;
    fdef.restitution = 0.6f;

    BodyDef bd = new BodyDef();
    bd.allowSleep = true;
    bd.position.set(x, y);
    Body body = world.createBody(bd);
    body.createFixture(fdef);
    if (isStatic) {
        body.setType(BodyDef.BodyType.StaticBody);
    }
    else {
        body.setType(BodyDef.BodyType.DynamicBody);
    }
    return body;
}
项目:GDX-Engine    文件:PhysicsManager.java   
/**
    * Create static body from a TiledObject Refer the box2d manual to
    * understand the static body
    * 
    * @param o
    *            TiledObject
    */
   public Body createStaticCircleBody(float x, float y, float radius) {
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;
// transform into box2d
x = x * WORLD_TO_BOX;
// get position-y of object from map
y = Gdx.graphics.getHeight() - y;
// transform into box2d
y = y * WORLD_TO_BOX;

groundBodyDef.position.set(x, y);
Body groundBody = world.createBody(groundBodyDef);
CircleShape shape = new CircleShape();
((CircleShape) shape).setRadius(radius * WORLD_TO_BOX / 2);
groundBody.createFixture(shape, 0.0f);
groundBody.setUserData("static");
return groundBody;
   }
项目:GDX-Engine    文件:PhysicsManager.java   
public Body createTempBody(float x, float y, FixtureDef fixtureDef) {
// Dynamic Body
BodyDef bodyDef = new BodyDef();
if (box2dDebug)
    bodyDef.type = BodyType.StaticBody;
else
    bodyDef.type = BodyType.DynamicBody;

// transform into box2d
x = x * WORLD_TO_BOX;
y = y * WORLD_TO_BOX;

bodyDef.position.set(x, y);

Body body = world.createBody(bodyDef);

Shape shape = new CircleShape();
((CircleShape) shape).setRadius(1 * WORLD_TO_BOX);

if (fixtureDef == null)
    throw new GdxRuntimeException("fixtureDef cannot be null!");
fixtureDef.shape = shape;
body.createFixture(fixtureDef);
return body;
   }
项目:GDX-Engine    文件:Rope.java   
private Body createRopeTipBody()
{
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DynamicBody;
    bodyDef.linearDamping = 0.5f;
    Body body = world.createBody(bodyDef);

    FixtureDef circleDef = new FixtureDef();
    CircleShape circle = new CircleShape();
    circle.setRadius(1.0f/PTM_RATIO);
    circleDef.shape = circle;
    circleDef.density = 10.0f;

    // Since these tips don't have to collide with anything
    // set the mask bits to zero
    circleDef.filter.maskBits = 0x01; //0;
    body.createFixture(circleDef);

    return body;
}
项目:GDX-Engine    文件:PhysicsTiledScene.java   
/**
 * Create static body from a TiledObject Refer the box2d manual to
 * understand the static body
 * 
 * @param o
 *            TiledObject
 */
public Body createStaticCircleBody(float x, float y, float radius) {
    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.type = BodyType.StaticBody;
    // transform into box2d
    x = x * WORLD_TO_BOX;
    // get position-y of object from map
    y = tileMapRenderer.getMapHeightUnits() - y;
    // transform into box2d
    y = y * WORLD_TO_BOX;

    groundBodyDef.position.set(x, y);
    Body groundBody = world.createBody(groundBodyDef);
    CircleShape shape = new CircleShape();
    ((CircleShape) shape).setRadius(radius * WORLD_TO_BOX / 2);
    groundBody.createFixture(shape, 0.0f);
    groundBody.setUserData("static");
    return groundBody;
}
项目:GDX-Engine    文件:PhysicsTiledScene.java   
public Body createTempBody(float x, float y, FixtureDef fixtureDef) {
    // Dynamic Body
    BodyDef bodyDef = new BodyDef();
    if (box2dDebug)
        bodyDef.type = BodyType.StaticBody;
    else
        bodyDef.type = BodyType.DynamicBody;

    // transform into box2d
    x = x * WORLD_TO_BOX;
    y = y * WORLD_TO_BOX;

    bodyDef.position.set(x, y);

    Body body = world.createBody(bodyDef);

    Shape shape = new CircleShape();
    ((CircleShape) shape).setRadius(1 * WORLD_TO_BOX);

    if (fixtureDef == null)
        throw new GdxRuntimeException("fixtureDef cannot be null!");
    fixtureDef.shape = shape;
    body.createFixture(fixtureDef);
    return body;
}
项目:FlappySpinner    文件:WorldUtils.java   
public static Body createSpinner(World world) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(Constants.SPINNER_POSITIONS);
    Body body = world.createBody(bodyDef);
    CircleShape circle = new CircleShape();
    circle.setRadius(Constants.SPINNER_SIZE);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = circle;
    fixtureDef.density = Constants.SPENNER_DENSITY;
    fixtureDef.friction = 0f;
    fixtureDef.restitution = 0.45f;
    body.createFixture(fixtureDef);
    circle.dispose();
    return body;
}
项目:school-game    文件:AttackHandler.java   
/**
 * Erzeugt automatisch einen Kreis als statischen Trigger.
 *
 * @see AttackHandler#createAttackFixture(Body, Shape)
 *
 * @param position der Mittelpunkt des Kreises
 * @param radius der Radius des Kreises
 */
public void createStaticAttackBody(Vector2 position, float radius)
{
    CircleShape circle = new CircleShape();

    circle.setPosition(new Vector2(position.x, position.y).scl(Physics.MPP));
    circle.setRadius(radius * Physics.MPP);

    BodyDef triggerDef = new BodyDef();
    triggerDef.type = BodyDef.BodyType.StaticBody;

    Body trigger = manager.getPhysicalWorld().createBody(triggerDef);

    createAttackFixture(trigger, circle);

    circle.dispose();
}
项目:fluffybalance    文件:Balanceball.java   
private void initBall() {
    float radius = 26;

    mBall = new Circle(0.f, 0.f, radius);

    mBallTextureRegion = new TextureRegion(new Texture(Gdx.files.internal("ball.png")));

    // create physics body
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(mBall.x, mBall.y);

    CircleShape ballShape = new CircleShape();
    ballShape.setRadius(mBall.radius - 2.f);

    mBallBody = mWorld.createBody(bodyDef);
    mBallBody.setUserData(new BodyUserDate(BODY_USER_DATA_TYPE_BALL));
    Fixture fixture = mBallBody.createFixture(ballShape, 0.5f);
    fixture.setFriction(BALL_FRICTION_BASE);
    fixture.setRestitution(0.4f);

    ballShape.dispose();
}
项目:QuackHack    文件:Player.java   
public void definePlayer(){
    BodyDef bdef = new BodyDef();
    bdef.position.set(100 / QuackHack.PPM, 1500 / QuackHack.PPM); // Mario start position
    bdef.type = BodyDef.BodyType.DynamicBody;
    b2body = world.createBody(bdef);

    FixtureDef fdef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setRadius(64 / QuackHack.PPM);

    fdef.filter.categoryBits = QuackHack.MARIO_BIT;
    fdef.filter.maskBits = QuackHack.DEFAULT_BIT;
    fdef.friction = 0;
    fdef.density = 0.1f;

    fdef.shape = shape;
    b2body.createFixture(fdef);
    b2body.createFixture(fdef).setUserData(this);
}
项目:advio    文件:Food.java   
public Food(World world, float x, float y, int size, float toGive) {
    super(x, y);
    color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
    outline = Advio.instance.darker(color);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    CircleShape shape = new CircleShape();
    shape.setRadius(size);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.1f;
    fd.shape = shape;
    fd.friction = 0.1f;
    // fd.filter.groupIndex = Advio.GROUP_BEINGS;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("food").add("toGive", toGive));
    shape.dispose();
}
项目:advio    文件:Player.java   
public Player(World world, float x, float y) {
    super(x, y);
    this.world = world;
    this.graphicsSize = 10;
    color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
    outline = Advio.instance.darker(color);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DynamicBody;
    bd.position.set(x, y);
    CircleShape shape = new CircleShape();
    shape.setRadius(50);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("player"));
    shape.dispose();
    // size * 2.25f
}
项目:advio    文件:Enemy.java   
public Enemy(World world, float x, float y, int size) {
    super(x, y);
    this.world = world;
    this.graphicsSize = 0.1f;
    color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
    outline = Advio.instance.darker(color);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DynamicBody;
    bd.position.set(x, y);
    CircleShape shape = new CircleShape();
    shape.setRadius(size);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("enemy").add("body", body));
    shape.dispose();
}
项目:RavTech    文件:CircleCollider.java   
@Override
public void apply () {
    Body body = ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).getBody();
    FixtureDef fixtureDef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setPosition(new Vector2(x, y));
    shape.setRadius(radius);
    fixtureDef.density = density;
    fixtureDef.friction = friction;
    fixtureDef.isSensor = isSensor;
    fixtureDef.restitution = restitution;
    fixtureDef.shape = shape;
    if (fixture != null) {
        dispose();
        fixture = null;
        ((Rigidbody)getParent().getComponentByType(ComponentType.Rigidbody)).apply();
        rebuildAll();
        getParent().transform.setRotation(getParent().transform.getRotation());
        return;
    }
    fixture = body.createFixture(fixtureDef);
    fixture.setFilterData(filter);
    UserData userdata = new UserData();
    userdata.component = (Rigidbody)getParent().getComponentByName("Rigidbody");
    fixture.setUserData(userdata);
}
项目:Dodgy-Dot    文件:GameScreen.java   
public Player (TextureRegion texture, float x, float y) {
    this.texture = texture;

    BodyDef ballD = new BodyDef();
    ballD.position.set(x, y);
    ballD.type = BodyType.DynamicBody;
    body = world.createBody(ballD);

    FixtureDef ballFD = new FixtureDef();
    ballShape = new CircleShape();
    ballShape.setRadius(BALL_WIDTH / 2);
    ballFD.shape = ballShape;
    ballFD.density = 1;
    ballFD.friction = 0;
    ballFD.restitution = 1;
    ballFD.filter.categoryBits = CATEGORY_PLAYER;
    ballFD.filter.maskBits = MASK_PLAYER;
    body.createFixture(ballFD);

    ballShape.dispose();
}
项目:Vector-Pinball-Editor    文件:Box2DFactory.java   
/** Creates a circle object with the given position and radius. Resitution defaults to 0.6.
 */
public static Body createCircle(World world, float x, float y, float radius, boolean isStatic) {
    CircleShape sd = new CircleShape();
    sd.setRadius(radius);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = sd;
    fdef.density = 1.0f;
    fdef.friction = 0.3f;
    fdef.restitution = 0.6f;

    BodyDef bd = new BodyDef();
    //bd.isBullet = true;
    bd.allowSleep = true;
    bd.position.set(x, y);
    Body body = world.createBody(bd);
    body.createFixture(fdef);
    if (isStatic) {
        body.setType(BodyDef.BodyType.StaticBody);
    }
    else {
        body.setType(BodyDef.BodyType.DynamicBody);
    }
    return body;
   }
项目:KillTheNerd    文件:BodyFactory.java   
public static Body createCircle() {
    if (!BodyFactory.initialized) {
        throw new IllegalStateException("You must initialize BodyFactory before using its functions");
    }
    final BodyDef testBodyDef2 = new BodyDef();
    testBodyDef2.position.set(2, 3);
    testBodyDef2.type = BodyDef.BodyType.DynamicBody;
    testBodyDef2.fixedRotation = true;
    final Body body2 = BodyFactory.world.createBody(testBodyDef2);
    final CircleShape testShape2 = new CircleShape();
    testShape2.setRadius(1f);
    final FixtureDef testFixtureDef2 = new FixtureDef();
    testFixtureDef2.shape = testShape2;
    testFixtureDef2.density = 25f;
    testFixtureDef2.friction = 1f;
    testFixtureDef2.restitution = 0;
    body2.createFixture(testFixtureDef2);
    final MassData md = body2.getMassData();
    md.mass = 80; // kg
    body2.setMassData(md);
    // System.out.println("circle - mass: " + body2.getMassData().mass + " density: " + body2.getFixtureList().get(0).getDensity());
    testShape2.dispose();
    return body2;
}
项目:Pong-Tutorial    文件:Ball.java   
public Ball(World world, float x, float y) {

    BodyDef bodyDef = new BodyDef();
    FixtureDef fixtureDef = new FixtureDef();
    this.world = world;

    // body definition
    bodyDef.type = BodyType.DynamicBody;
    bodyDef.position.set(x, y);

    // ball shape
    CircleShape ballShape = new CircleShape();
    ballShape.setRadius(RADIUS);

    // fixture definition
    fixtureDef.shape = ballShape;
    fixtureDef.friction = 0;
    fixtureDef.restitution = 1;
    //fixtureDef.density = 0;

    body = world.createBody(bodyDef);
    fixture = body.createFixture(fixtureDef);

    ballShape.dispose();
}
项目:GDXJam    文件:EntityFactory.java   
public EntityBuilder circleSensor (float radius) {
    CircleShape shape = new CircleShape();
    shape.setRadius(radius);

    PhysicsComponent physics = Components.PHYSICS.get(entity);
    if (physics == null) {
        physicsBody(DEFAULT_BODY);
    }

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.isSensor = true;
    fixtureDef.shape = shape;

    physics.getBody().createFixture(fixtureDef);
    return this;
}
项目:OdysseeDesMaths    文件:Hero.java   
public void defineHero(){
    BodyDef bdef = new BodyDef();
    bdef.position.set(64 / TreeScreen.PPM, 32 / TreeScreen.PPM);
    bdef.type = BodyDef.BodyType.DynamicBody;
    b2body = world.createBody(bdef);

    FixtureDef fdef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setRadius(SIZE_HERO / 2 / TreeScreen.PPM);
    fdef.filter.categoryBits = TreeScreen.HERO_BIT;
    fdef.filter.maskBits = TreeScreen.GROUND_BIT;

    fdef.shape = shape;
    b2body.createFixture(fdef).setUserData(this);

    EdgeShape head = new EdgeShape();
    head.set(new Vector2(-2 / TreeScreen.PPM, 6 / TreeScreen.PPM), new Vector2(2 / TreeScreen.PPM, 6 / TreeScreen.PPM));
    fdef.filter.categoryBits = TreeScreen.HERO_HEAD_BIT;
    fdef.shape = head;
    fdef.isSensor = true;

    b2body.createFixture(fdef).setUserData(this);
}
项目:libgdx_mario    文件:Mario.java   
private void defineMario() {
    BodyDef bdef = new BodyDef();
    bdef.position.set(60 / MarioBros.PPM, 32 / MarioBros.PPM);
    bdef.type = BodyDef.BodyType.DynamicBody;
    b2body = world.createBody(bdef);

    FixtureDef fdef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setRadius(6 / MarioBros.PPM);

    fdef.filter.categoryBits = MarioBros.MARIO_BIT;
    fdef.filter.maskBits = MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.ITEM_BIT
            | MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT;
    fdef.shape = shape;

    b2body.createFixture(fdef).setUserData(this);

    EdgeShape head = new EdgeShape();
    head.set(new Vector2(-2 / MarioBros.PPM, 7 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 7 / MarioBros.PPM));
    fdef.shape = head;
    fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT;
    fdef.isSensor = true;

    b2body.createFixture(fdef).setUserData(this);
}
项目:libgdx_mario    文件:Mushroom.java   
@Override
protected void defineItem() {
    BodyDef bdef = new BodyDef();
    bdef.position.set(getX(), getY());
    bdef.type = BodyDef.BodyType.DynamicBody;
    b2body = world.createBody(bdef);

    FixtureDef fdef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setRadius(6 / MarioBros.PPM);
    fdef.filter.categoryBits = MarioBros.ITEM_BIT;
    fdef.filter.maskBits = MarioBros.MARIO_BIT | MarioBros.OBJECT_BIT |
            MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT;
    fdef.shape = shape;
    b2body.createFixture(fdef).setUserData(this);
}
项目:RottenCave    文件:Character.java   
private void createPlayerBody() {
    // je cree la def (position/type...)
    BodyDef characterBodyDef = new BodyDef();
    characterBodyDef.type = BodyDef.BodyType.DynamicBody;
    characterBodyDef.position.set(starterX, starterY);

    // je cree ma fixture qui fix les carac physiques du body et sa shape
    FixtureDef characterFixtureDef = new FixtureDef();
    characterFixtureDef.density = 1;
    characterFixtureDef.restitution = 1.0f;
    characterFixtureDef.friction = 0.5f;

    // je cree mon body dans mon world partant de ma def
    body = world.createBody(characterBodyDef);

    CircleShape circleShape = new CircleShape();
    if (player) {
        circleShape.setRadius(PLAYER_RADIUS);
    } else {
        circleShape.setRadius(MONSTER_RADIUS);
    }

    characterFixtureDef.shape = circleShape;

    body.createFixture(characterFixtureDef);
}
项目:SupaBax    文件:BodyBuilder.java   
/**
 * 
 * @param world
 * @param ellipseObject
 * @param density
 * @param friction
 * @param restitution
 */
private void createEllipse(World world, EllipseMapObject ellipseObject, float density, float friction, float restitution){
    Ellipse circle = ellipseObject.getEllipse();
    CircleShape shape = new CircleShape();
    shape.setRadius(circle.width / 2f / SupaBox.PPM);

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.position.set(new Vector2((circle.x + circle.width / 2f) / SupaBox.PPM, (circle.y + circle.width / 2f) / SupaBox.PPM));

    Body body = world.createBody(bodyDef);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.density = density;
    fixtureDef.friction = friction;
    fixtureDef.restitution = restitution;

    body.createFixture(fixtureDef);

    shape.dispose();
}
项目:Little-Nibolas    文件:Ball.java   
public Ball(World world, float x, float y) {

    BodyDef bodyDef = new BodyDef();
    FixtureDef fixtureDef = new FixtureDef();
    this.world = world;

    // body definition
    bodyDef.type = BodyType.DynamicBody;
    bodyDef.position.set(x, y);

    // ball shape
    CircleShape ballShape = new CircleShape();
    ballShape.setRadius(RADIUS);

    // fixture definition
    fixtureDef.shape = ballShape;
    fixtureDef.friction = .25f;
    fixtureDef.restitution = 0.9f;
    fixtureDef.density = 2.5f;

    body = world.createBody(bodyDef);
    fixture = body.createFixture(fixtureDef);

    ballShape.dispose();
}
项目:Little-Nibolas    文件:Escudo.java   
public Escudo(World world, ScreenRome pantalla, float x, float y, float width, float height) {
    WIDTH = width;
    HEIGHT = width * 2;
    this.world = world;
    this.pantalla = pantalla;

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.position.set(x, y);
    bodyDef.fixedRotation = true;

    CircleShape shape = new CircleShape();
    shape.setRadius(width/2);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.friction = .5f;
    fixtureDef.restitution = 0;
    fixtureDef.density = 2.5f;

    body = world.createBody(bodyDef);
    fixture = body.createFixture(fixtureDef);

    shape.dispose();

}
项目:Little-Nibolas    文件:Ball.java   
public Ball(World world, float x, float y) {

    BodyDef bodyDef = new BodyDef();
    FixtureDef fixtureDef = new FixtureDef();
    this.world = world;

    // body definition
    bodyDef.type = BodyType.DynamicBody;
    bodyDef.position.set(x, y);

    // ball shape
    CircleShape ballShape = new CircleShape();
    ballShape.setRadius(RADIUS);

    // fixture definition
    fixtureDef.shape = ballShape;
    fixtureDef.friction = .25f;
    fixtureDef.restitution = 0.9f;
    fixtureDef.density = 2.5f;

    body = world.createBody(bodyDef);
    fixture = body.createFixture(fixtureDef);

    ballShape.dispose();
}
项目:libgdxcn    文件:KinematicBodyTest.java   
public void create () {
    cam = new OrthographicCamera(48, 32);
    cam.position.set(0, 15, 0);
    renderer = new Box2DDebugRenderer();

    world = new World(new Vector2(0, -10), true);
    Body body = world.createBody(new BodyDef());
    CircleShape shape = new CircleShape();
    shape.setRadius(1f);
    MassData mass = new MassData();
    mass.mass = 1f;
    body.setMassData(mass);
    body.setFixedRotation(true);
    body.setType(BodyType.KinematicBody);
    body.createFixture(shape, 1);
    body.setBullet(true);
    body.setTransform(new Vector2(0, 0), body.getAngle());
    body.setLinearVelocity(new Vector2(50f, 0));
}
项目:libgdxcn    文件:Box2DCharacterControllerTest.java   
private Body createPlayer () {
    BodyDef def = new BodyDef();
    def.type = BodyType.DynamicBody;
    Body box = world.createBody(def);

    PolygonShape poly = new PolygonShape();
    poly.setAsBox(0.45f, 1.4f);
    playerPhysicsFixture = box.createFixture(poly, 1);
    poly.dispose();

    CircleShape circle = new CircleShape();
    circle.setRadius(0.45f);
    circle.setPosition(new Vector2(0, -1.4f));
    playerSensorFixture = box.createFixture(circle, 0);
    circle.dispose();

    box.setBullet(true);

    return box;
}
项目:jumplings    文件:IntroActor.java   
@Override
protected void initBodies(PointF worldPos) {

    // Cuerpo
    {
        // Create Shape with Properties
        CircleShape circleShape = new CircleShape();
        circleShape.setRadius(mRadius);
        mMainBody = getWorld().createBody(this, worldPos, true);
        mMainBody.setBullet(true);

        // Assign shape to Body
        Fixture f = mMainBody.createFixture(circleShape, 1.0f);
        f.setFilterData(CONTACT_FILTER);
        circleShape.dispose();

    }

    mAnthtopoDelegate.createAnthropomorphicLimbs(worldPos, mRadius);
}
项目:jumplings    文件:DoubleSonEnemyActor.java   
@Override
protected void initBodies(PointF worldPos) {

    // Cuerpo
    {
        // Create Shape with Properties
        CircleShape circleShape = new CircleShape();
        circleShape.setRadius(mRadius);
        mMainBody = getWorld().createBody(this, worldPos, true);
        mMainBody.setBullet(true);

        // Assign shape to Body
        Fixture f = mMainBody.createFixture(circleShape, 1.0f);
        f.setFilterData(CONTACT_FILTER);
        circleShape.dispose();

    }

    mAnthtopoDelegate.createAnthropomorphicLimbs(worldPos, mRadius);
}
项目:jumplings    文件:RoundEnemyActor.java   
@Override
protected void initBodies(PointF worldPos) {

    // Cuerpo
    {
        // Create Shape with Properties
        CircleShape circleShape = new CircleShape();
        circleShape.setRadius(mRadius);
        mMainBody = getWorld().createBody(this, worldPos, true);
        mMainBody.setBullet(true);

        // Assign shape to Body
        Fixture f = mMainBody.createFixture(circleShape, 1.0f);
        f.setFilterData(CONTACT_FILTER);
        circleShape.dispose();

    }

    mAnthtopoDelegate.createAnthropomorphicLimbs(worldPos, mRadius);
}
项目:jumplings    文件:SparksActor.java   
@Override
protected void initBodies(PointF worldPos) {

    // Cuerpo
    {
        // Create Shape with Properties
        CircleShape circleShape = new CircleShape();
        circleShape.setRadius(mRadius);
        mMainBody = getWorld().createBody(this, worldPos, true);
        mMainBody.setBullet(true);

        // Assign shape to Body
        Fixture f = mMainBody.createFixture(circleShape, 1.0f);
        f.setFilterData(SPARKS_FILTER);
        circleShape.dispose();
    }

}
项目:box2dlights    文件:Box2dLightTest.java   
private void createBoxes() {
    CircleShape ballShape = new CircleShape();
    ballShape.setRadius(RADIUS);

    FixtureDef def = new FixtureDef();
    def.restitution = 0.9f;
    def.friction = 0.01f;
    def.shape = ballShape;
    def.density = 1f;
    BodyDef boxBodyDef = new BodyDef();
    boxBodyDef.type = BodyType.DynamicBody;

    for (int i = 0; i < BALLSNUM; i++) {
        // Create the BodyDef, set a random position above the
        // ground and create a new body
        boxBodyDef.position.x = -20 + (float) (Math.random() * 40);
        boxBodyDef.position.y = 10 + (float) (Math.random() * 15);
        Body boxBody = world.createBody(boxBodyDef);
        boxBody.createFixture(def);
        balls.add(boxBody);
    }
    ballShape.dispose();
}
项目:old48_30_game    文件:TilePresetFactory.java   
private MushroomedCrab createCrub(float posX, float posY) {
    // PolygonShape crubShape = new PolygonShape();
    CircleShape crubShape = new CircleShape();
    // crubShape.setAsBox(Constants.CRAB_WIDTH / 2, Constants.CRAB_HEIGHT /
    // 2);
    crubShape.setRadius(Constants.CRAB_WIDTH / 2);
    PhysicsModel crubModel = new PhysicsModel(world, posX, posY,
            crubShape,
            true, BodyDef.BodyType.DynamicBody, 1.0f);
    MushroomedCrab mush = new MushroomedCrab(crubModel);
    mush.moveLeft();
    // if (new Random().nextInt() % 2 == 0)
    // mush.moveRight();
    // else
    // mush.moveLeft();

    return mush;
}
项目:old48_30_game    文件:GameScreen.java   
private Player createPlayer(World world, Cable cable) {
    CircleShape playerShape = new CircleShape();
    playerShape.setRadius(Constants.PLAYER_WIDTH / 2);
    PhysicsModel playerModel = new PhysicsModel(world, 0, 5, playerShape,
            true, BodyDef.BodyType.DynamicBody, 0.1f);
    Player player = new Player(playerModel);

    RevoluteJointDef jointDef = new RevoluteJointDef();
    jointDef.bodyA = player.getBody();
    jointDef.bodyB = cable.getBodyList().get(0);
    world.createJoint(jointDef);

    WeldJointDef weldJointDef = new WeldJointDef();
    weldJointDef.bodyA = player.getBody();
    weldJointDef.bodyB = cable.getBodyList().get(
            cable.getBodyList().size() - 1);
    weldJointDef.localAnchorA.set(-30, 8);
    world.createJoint(weldJointDef);

    return player;
}
项目:libgdx-demo-vector-pinball    文件:Box2DFactory.java   
/** Creates a circle object with the given position and radius. Resitution defaults to 0.6. */
public static Body createCircle (World world, float x, float y, float radius, boolean isStatic) {
    CircleShape sd = new CircleShape();
    sd.setRadius(radius);

    FixtureDef fdef = new FixtureDef();
    fdef.shape = sd;
    fdef.density = 1.0f;
    fdef.friction = 0.3f;
    fdef.restitution = 0.6f;

    BodyDef bd = new BodyDef();
    // bd.isBullet = true;
    bd.allowSleep = true;
    bd.position.set(x, y);
    Body body = world.createBody(bd);
    body.createFixture(fdef);
    if (isStatic) {
        body.setType(BodyDef.BodyType.StaticBody);
    } else {
        body.setType(BodyDef.BodyType.DynamicBody);
    }
    return body;
}
项目:crabox    文件:Utils.java   
public static Body createBallBody(float x, float y, float radius, BodyType type, float density, float friction, float restitution, World world) {
    final BodyDef def = new BodyDef();
    def.position.set(x, y);
    def.type = type;

    CircleShape shape = new CircleShape();
    shape.setRadius(radius);

    FixtureDef fixt = new FixtureDef();
    fixt.shape = shape;
    fixt.density = density;
    fixt.friction = friction;
    fixt.restitution = restitution;

    Body bb = world.createBody(def);
    bb.createFixture(fixt);

    shape.dispose();

    return bb;
}
项目:gdx-ai    文件:Box2dSteeringTest.java   
public Box2dSteeringEntity createSteeringEntity (World world, TextureRegion region, boolean independentFacing, int posX, int posY) {

        CircleShape circleChape = new CircleShape();
        circleChape.setPosition(new Vector2());
        int radiusInPixels = (int)((region.getRegionWidth() + region.getRegionHeight()) / 4f);
        circleChape.setRadius(Box2dSteeringTest.pixelsToMeters(radiusInPixels));

        BodyDef characterBodyDef = new BodyDef();
        characterBodyDef.position.set(Box2dSteeringTest.pixelsToMeters(posX), Box2dSteeringTest.pixelsToMeters(posY));
        characterBodyDef.type = BodyType.DynamicBody;
        Body characterBody = world.createBody(characterBodyDef);

        FixtureDef charFixtureDef = new FixtureDef();
        charFixtureDef.density = 1;
        charFixtureDef.shape = circleChape;
        charFixtureDef.filter.groupIndex = 0;
        characterBody.createFixture(charFixtureDef);

        circleChape.dispose();

        return new Box2dSteeringEntity(region, characterBody, independentFacing, Box2dSteeringTest.pixelsToMeters(radiusInPixels));
    }
项目:Blob-Game    文件:ExplodeBall.java   
public ExplodeBall(Level level, long id) {
    super(level, id);
    thisID = id;
    mName = "lightbulb";
    mTex = "data/"+Game.get().getBodyEditorLoader().getImagePath(mName);
    Vector2 origin = new Vector2();
    mBody = makeBody(mName, 64, BodyType.DynamicBody, origin, false);
    ((CompositeDrawable)mDrawable).mDrawables.add(new BodySprite(mBody, origin, mTex));

    CircleShape circle = new CircleShape();
    circle.setPosition(new Vector2(0,0));
    circle.setRadius(detectRadius);
    FixtureDef fd = new FixtureDef();
    fd.shape = circle;
    fd.isSensor = true;
    mSensorBall = mBody.createFixture(fd);
    explodeTime = 180;

    mExplodeTimer = new Timer();
    mExplodeTimer.setTimer(explodeTime);
    mExplodeTimer.unpause();

    setProp("Density", 0.3);
}