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

项目:GDX-Engine    文件:PhysicsManager.java   
/**
    * Create static body from a TiledObject Refer the box2d manual to
    * understand the static body
    * 
    * @param o
    *            TiledObject
    */
   public Body createStaticBoxBody(float x, float y, float width, float height) {
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;

// transform into box2d
x = x * WORLD_TO_BOX;

// get position-y 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);
PolygonShape polygon = new PolygonShape();
((PolygonShape) polygon).setAsBox(width * WORLD_TO_BOX / 2, height
    * WORLD_TO_BOX / 2);
groundBody.createFixture(polygon, 0.0f);
groundBody.setUserData("static");
return groundBody;
   }
项目: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 createStaticBoxBody(float x, float y, float width, float height) {
    BodyDef groundBodyDef = new BodyDef();
    groundBodyDef.type = BodyType.StaticBody;

    // transform into box2d
    x = x * WORLD_TO_BOX;

    // get position-y from map
    y = tileMapRenderer.getMapHeightUnits() - y;
    // transform into box2d
    y = y * WORLD_TO_BOX;

    groundBodyDef.position.set(x, y);
    Body groundBody = world.createBody(groundBodyDef);
    PolygonShape polygon = new PolygonShape();
    ((PolygonShape) polygon).setAsBox(width * WORLD_TO_BOX / 2, height
            * WORLD_TO_BOX / 2);
    groundBody.createFixture(polygon, 0.0f);
    groundBody.setUserData("static");
    return groundBody;
}
项目: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;
}
项目:water2d-libgdx    文件:GameMain.java   
private void createBody() {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DynamicBody;

    // Set our body's starting position in the world
    bodyDef.position.set(Gdx.input.getX() / 100f, camera.viewportHeight - Gdx.input.getY() / 100f);

    // Create our body in the world using our body definition
    Body body = world.createBody(bodyDef);

    // Create a circle shape and set its radius to 6
    PolygonShape square = new PolygonShape();
    square.setAsBox(0.3f, 0.3f);

    // Create a fixture definition to apply our shape to
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = square;
    fixtureDef.density = 0.5f;
    fixtureDef.friction = 0.5f;
    fixtureDef.restitution = 0.5f;

    // Create our fixture and attach it to the body
    body.createFixture(fixtureDef);

    square.dispose();
}
项目:cgc-game    文件:SpotlightCop.java   
public SpotlightCop(CGCWorld theWorld, Animation newLowAnimation, 
        Animation newMidAnimation, Animation newHighAnimation, 
        EntityType pEntityType, Body attachedBody, short pID, 
        float cameraPosX, float cameraPosY)
{
    super(theWorld, newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody, pID);

    body.getFixtureList().get(0).setSensor(true);

    // Create spotlight
    Body b = CGCWorld.getBF().createCircle(cameraPosX, cameraPosY, 
            2.1f, BodyType.DynamicBody, BodyFactory.CAT_INTERACTABLE, BodyFactory.MASK_INTERACTABLE);
    b.getFixtureList().get(0).setSensor(true);
    b.setFixedRotation(true);
    spotlight = new Spotlight(null, null, TextureAnimationDrawer.spotlightAnim,
            EntityType.TARGETER, b, CGCWorld.getCamera(), getPID());
    b.setUserData(spotlight);
    spotlight.addToWorldLayers(CGCWorld.getLH());

    alive = true;
    lowState = AnimationState.STAND;
}
项目:cgc-game    文件:SteelHorseRider.java   
private void fire()
{
    if (target != null) // If null, the targeter is missing somehow
    {
        // Create a bullet to fire
        Body b = CGCWorld.getBF().createCircle(body.getWorldCenter().x, 
                body.getWorldCenter().y, 
                0.1f, BodyType.DynamicBody, BodyFactory.CAT_INTERACTABLE, BodyFactory.MASK_INTERACTABLE);
        GameEntity ge = new RiderBullet(null, null, com.percipient24.cgc.art.TextureAnimationDrawer.bulletAnim, EntityType.BULLET,
                b, target.getBody().getPosition(), 
                new Vector2(target.getHighRegion().getRegionWidth() / 2,
                        target.getHighRegion().getRegionHeight() / 2), false);
        b.setUserData(ge);

        ge.addToWorldLayers(CGCWorld.getLH());
    }
}
项目:cgc-game    文件:SteelHorse.java   
public SteelHorse(Animation newLowAnimation, Animation newMidAnimation,
        Animation newHighAnimation, EntityType pEntityType, Body attachedBody)
{
    super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody);

    setTimers();

    hp = MAX_HP;

    offset = (float) ((Math.random() - 0.5f) * accuracy);

    target = CGCWorld.getPrisoners().random();

    Vector2 sheriffPos = body.getWorldCenter().cpy().sub(new Vector2(0, getImageHalfHeight(0) / 2).rotate(rotation));
    Body b = CGCWorld.getBF().createCircle(0, 0, 
            0.6f, BodyType.StaticBody, BodyFactory.CAT_IMPASSABLE, BodyFactory.MASK_SHERIFF_GROUND);

    sheriff = new Sheriff(com.percipient24.cgc.art.TextureAnimationDrawer.sheriffAnim, com.percipient24.cgc.art.TextureAnimationDrawer.sheriffAnim, com.percipient24.cgc.art.TextureAnimationDrawer.sheriffAnim, EntityType.SHERIFF, b, this);
    sheriff.addToWorldLayers(CGCWorld.getLH());
    //sheriff.addTargeter();
    b.setUserData(sheriff);
    b.setTransform(sheriffPos, 0);

}
项目:cgc-game    文件:Sheriff.java   
public void addTargeter()
{
    if(targeter == null)
    {
        Body bod = CGCWorld.getBF().createCircle(body.getWorldCenter().cpy().x, 
                body.getWorldCenter().cpy().y, 0.5f, BodyType.DynamicBody, 
                BodyFactory.CAT_NON_INTERACTIVE, BodyFactory.MASK_NON_INTERACTIVE);
        bod.getFixtureList().get(0).setSensor(true);
        bod.setFixedRotation(true);

        targeter = new Targeter(null, null, com.percipient24.cgc.art.TextureAnimationDrawer.targetingAnims[0], EntityType.TARGETER, bod, CGCWorld.getCamera(), -1);
        bod.setUserData(targeter);

        targeter.addToWorldLayers(CGCWorld.getLH());

        TimerManager.addTimer(fireTimer);
    }
}
项目:cgc-game    文件:TankBuilder.java   
public Boss createBoss()
{
    Boss boss;
    Body bossBody = CGCWorld.getBF().createRectangle(9.5f, 0, 20f, 0.5f, BodyType.DynamicBody, 
        BodyFactory.CAT_BOSS, BodyFactory.MASK_BOSS);
    if (aiControl)
    {
        boss = new Tank(TextureAnimationDrawer.tankAnims[0], TextureAnimationDrawer.tankAnims[1],
                TextureAnimationDrawer.tankAnims[2], EntityType.TANK, bossBody, aiControl, null);
    }
    else
    {
        boss = new Tank(TextureAnimationDrawer.tankAnims[0], TextureAnimationDrawer.tankAnims[1],
                TextureAnimationDrawer.tankAnims[2], EntityType.TANK, bossBody, aiControl, tankControl.getTarget());
    }
    bossBody.setUserData(boss);
    bossBody.setFixedRotation(true);
    bossBody.setLinearDamping(50.0f);

    boss.addToWorldLayers(CGCWorld.getLH());

    return boss;
}
项目:cgc-game    文件:SteelHorseBuilder.java   
public Boss createBoss() 
{
    Boss boss;
    Body bossBody;

    bossBody = CGCWorld.getBF().createRectangle(9.0f, 5.0f, 1.0f, 2.0f, 
            BodyType.DynamicBody, 
            BodyFactory.CAT_STEEL_HORSE, BodyFactory.MASK_STEEL_HORSE);
    boss = new SteelHorse(TextureAnimationDrawer.steelHorseAnim,
            TextureAnimationDrawer.steelHorseAnim, TextureAnimationDrawer.steelHorseAnim,
            EntityType.STEEL_HORSE, bossBody);
    bossBody.setUserData(boss);
    bossBody.setFixedRotation(true);
    bossBody.setLinearDamping(0.1f);

    boss.addToWorldLayers(CGCWorld.getLH());

    return boss;
}
项目:cgc-game    文件:Camera.java   
public void createWalls()
{
    Body b = CGCWorld.getBF().createRectangle(position.x + viewportWidth / 2, position.y+ (viewportHeight + wallHeight / 2), 
                    viewportWidth,wallHeight, BodyType.DynamicBody,
                    BodyFactory.CAT_IMPASSABLE, BodyFactory.MASK_PLAYER_WALL);
    upperWall = new PlayerWall(EntityType.PLAYERWALL, b, true);
    b.setUserData(upperWall);
    upperWall.addToWorldLayers(CGCWorld.getLH());

    Body b2 = CGCWorld.getBF().createRectangle(position.x + viewportWidth / 2, position.y - viewportHeight + wallHeight / 2, 
                    viewportWidth, wallHeight, BodyType.DynamicBody,
                    BodyFactory.CAT_IMPASSABLE, BodyFactory.MASK_PLAYER_WALL);
    lowerWall = new PlayerWall(EntityType.PLAYERWALL, b2, false);
    b2.setUserData(lowerWall);
    lowerWall.addToWorldLayers(CGCWorld.getLH());
}
项目:Undertailor    文件:WorldObject.java   
public WorldObject() {
    this.id = nextId++;
    this.destroyed = false;
    this.boundingQueue = new ObjectSet<>();
    this.def = new BodyDef();
    this.persistent = false;
    this.visible = true;
    this.layer = 0;

    this.def.active = true;
    this.def.awake = true;
    this.def.fixedRotation = true;
    this.def.type = BodyType.DynamicBody;

    this.groupId = -1;
    this.canCollide = true;
    this.events = new EventHelper(this);
}
项目:M-M    文件:Bonus.java   
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.HALF_SIZE, Block.HALF_SIZE);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.isSensor = true;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BLOCK;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    shape.dispose();
    return body;
}
项目:M-M    文件:Block.java   
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(HALF_SIZE, HALF_SIZE);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.restitution = 1f;
    fixtureDef.friction = 0f;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BLOCK;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    shape.dispose();
    return body;
}
项目:M-M    文件:BoundsEntity.java   
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final ChainShape shape = new ChainShape();
    final float w = Box2DUtil.WIDTH * 2f / 5f, h = Box2DUtil.HEIGHT * 2f / 5f;
    shape.createLoop(new float[] { -w, -h, -w, h, w, h, w, -h });
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.restitution = 0.9f;
    fixtureDef.friction = 0.2f;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BOUNDS;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    return body;
}
项目: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    文件:Block.java   
public Block(World world, float x, float f, BodyType type, boolean invisible) {
    BodyDef bd = new BodyDef();
    bd.type = type;
    bd.position.set(x, f);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(size / 2, size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.1f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.filter.groupIndex = Advio.GROUP_DONT_COLLIDE_WITH_PLAYER;
    // fd.filter.groupIndex = Advio.GROUP_SCENERY;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("block"));
    this.invisible = invisible;
    shape.dispose();
}
项目:advio    文件:PressurePlate.java   
public PressurePlate(Level l, World world, float x, float y, float weight, Block[] blocks) {
    super(x, y);
    this.level = l;
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.size / 2, Block.size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.isSensor = true;
    this.blocks = new ArrayList<Block>(Arrays.asList(blocks));
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("plate").add("pressed", false).add("weight", weight));
    shape.dispose();
    this.world = world;
}
项目: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    文件:AgarLogic.java   
public AgarLogic(Level l, World world, float x, float y) {
    super(x, y);
    this.level = l;
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.size / 2, Block.size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.isSensor = true;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("agariologic"));
    shape.dispose();
    this.world = world;
}
项目: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();
}
项目:advio    文件:Goal.java   
public Goal(World world, float x, float y) {
    super(x, y);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.size / 2, Block.size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.1f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.isSensor = true;
    // fd.filter.groupIndex = Advio.GROUP_SCENERY;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("goal"));
    shape.dispose();
}
项目:RavTech    文件:Rigidbody.java   
@Override
public void setVariable (int variableID, Object value) {
    switch (variableID) {
        case 0:
            getBody().setAngularDamping(Float.valueOf(String.valueOf(value)));
            break;
        case 1:
            getBody().setBullet(Boolean.valueOf(String.valueOf(value)));
            break;
        case 2:
            getBody().setFixedRotation(Boolean.valueOf(String.valueOf(value)));
            break;
        case 3:
            getBody().setGravityScale(Float.valueOf(String.valueOf(value)));
            break;
        case 4:
            getBody().setLinearDamping(Float.valueOf(String.valueOf(value)));
            break;
        case 5:
            getBody().setType(value.equals("StaticBody") || value.equals("Static") ? BodyType.StaticBody
                : value.equals("DynamicBody") || value.equals("Dynamic") ? BodyType.DynamicBody
                    : value.equals("KinematicBody") || value.equals("Kinematic") ? BodyType.KinematicBody : (BodyType)value);
    }
}
项目:DropTheCube-LD32    文件:EntityUtils.java   
public static final Entity createPlayer(){
    Entity entity = new Entity();

    SpriteComponent spriteComponent = new SpriteComponent();
    Texture texture = new Texture(Gdx.files.internal("Player.png"));
    Sprite sprite = new Sprite(texture);
    sprite.setPosition(CameraSize.getWidth() - Values.TILED_SIZE_PIXELS * 3, CameraSize.getHeight() / 2 - sprite.getHeight());
    sprite.setScale(1.5f);
    spriteComponent.sprite = sprite;

    Box2DComponent box2DComponent = Box2DUtils.create(sprite, BodyType.DynamicBody);

    PlayerComponent playerComponent = new PlayerComponent();

    HealthComponent healthComponent = new HealthComponent();
    healthComponent.health = new Health(Values.MAX_HEALTH);
    healthComponent.heartTexture = new Texture(Gdx.files.internal("heart.png"));

    ScoreComponent scoreComponent = new ScoreComponent();

    AshleyUtils.addComponents(entity, spriteComponent, box2DComponent, playerComponent, healthComponent, scoreComponent);

    box2DComponent.fixture.setUserData(entity);

    return entity;
}
项目:TheEndlessCastle    文件:ProjectileEntity.java   
private BodyComponent SetBody(String name)
{
    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set(_position.x, _position.y);
    bodyDef.type = BodyType.DynamicBody;
    bodyDef.fixedRotation = _descriptor.FixedRotation;
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.density = _descriptor.Density;
    fixtureDef.friction = 0.7f;
    fixtureDef.restitution = 0f;
    _bodyCompo = new BodyComponent(name, this, _box2DWorld, _bodyDAL, bodyDef, fixtureDef);
    _bodyCompo.setActive(false);
    _bodyCompo.setUserData(this);
    addComponent(_bodyCompo);
    return _bodyCompo;
}
项目:LibGDX-MVC-Tutorial    文件:Helpers.java   
public static Body initBody(World world, float x, float y, float width, float height, boolean rotate, float gravityScale, float density)
{
    BodyDef bodyDef = new BodyDef();
    bodyDef.position.set((x + width / 2), (y + height / 2));

    bodyDef.fixedRotation = !rotate;
    bodyDef.type = BodyType.DynamicBody;

    Body body = world.createBody(bodyDef);
    body.setGravityScale(gravityScale);

    PolygonShape shape = new PolygonShape();
    shape.setAsBox((width / 2), (height / 2));
    body.createFixture(shape, density);
    shape.dispose();

    return body;
}
项目: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();
}
项目:Dodgy-Dot    文件:GameScreen.java   
Enemy (TextureRegion texture) {
    this.texture = texture;

    BodyDef squareD = new BodyDef();
    squareD.type = BodyType.KinematicBody;
    squareD.position.set((float) Math.random() * SCREEN_WIDTH, SCREEN_HEIGHT + 3.0f);
    //squareD.linearVelocity.set(0.0f, -((float) Math.random() * (SQUARE_MAX_SPEED - SQUARE_MIN_SPEED)) + SQUARE_MIN_SPEED);
    //squareD.angularVelocity = (SQUARE_MAX_SPEED + squareD.linearVelocity.y) * (Math.random() >= 0.5f ? 1 : -1);
    squareD.gravityScale = 0;
    body = world.createBody(squareD);

    FixtureDef squareFD = new FixtureDef();
    squareFD.shape = squareShape;
    //squareFD.density = 99999999;
    squareFD.friction = 0;
    squareFD.restitution = 1;
    squareFD.filter.categoryBits = CATEGORY_ENEMY;
    squareFD.filter.maskBits = MASK_ENEMY;
    body.createFixture(squareFD);
}
项目:Aftamath    文件:Warp.java   
@Override
public void create() {
    init = true;
    PolygonShape shape = new PolygonShape();
    shape.setAsBox((rw)/Vars.PPM, (rh)/Vars.PPM);

    bdef.position.set(x/Vars.PPM, y/Vars.PPM);
    bdef.type = BodyType.KinematicBody;
    fdef.shape = shape;

    fdef.isSensor = true;
    body = world.createBody(bdef);
    body.setUserData(this);
    fdef.filter.maskBits = (short) ( Vars.BIT_GROUND | Vars.BIT_BATTLE| Vars.BIT_LAYER1| Vars.BIT_PLAYER_LAYER| Vars.BIT_LAYER3);
    fdef.filter.categoryBits = (short) ( Vars.BIT_GROUND | Vars.BIT_BATTLE| Vars.BIT_LAYER1| Vars.BIT_PLAYER_LAYER| Vars.BIT_LAYER3);
    body.createFixture(fdef).setUserData(Vars.trimNumbers(ID));

    createCenter();
}
项目:Aftamath    文件:Entity.java   
public void create(){
    init = true;
    //hitbox
    PolygonShape shape = new PolygonShape();
    shape.setAsBox((rw)/PPM, (rh)/PPM);

    bdef.position.set(x/PPM, y/PPM);
    bdef.type = BodyType.KinematicBody;
    fdef.shape = shape;
    body = world.createBody(bdef);
    body.setUserData(this);
    fdef.filter.maskBits = (short) (layer | Vars.BIT_GROUND | Vars.BIT_BATTLE);
    fdef.filter.categoryBits = layer;
    body.createFixture(fdef).setUserData(Vars.trimNumbers(ID));
    body.setMassData(mdat);

    createCenter();
    if(!main.exists(this)) main.addObject(this);
}
项目:Aftamath    文件:Ground.java   
public void create(){
    init = true;
    bdef.type = BodyType.StaticBody;
    bdef.position.set(x, y);

    ChainShape cs = new ChainShape();
    Vector2[] v = new Vector2[5];

    v[0] = new Vector2(-TILE_SIZE / 2 / PPM, -TILE_SIZE / 2 / PPM);
    v[1] = new Vector2(-TILE_SIZE / 2 / PPM, TILE_SIZE / 2 / PPM);
    v[2] = new Vector2(TILE_SIZE / 2 / PPM, TILE_SIZE / 2 / PPM);
    v[3] = new Vector2(TILE_SIZE / 2 / PPM, -TILE_SIZE / 2 / PPM);
    v[4] = new Vector2(-Vars.TILE_SIZE / 2 / Vars.PPM, -Vars.TILE_SIZE / 2 / Vars.PPM);
    cs.createChain(v);

    fdef.friction = .25f;
    fdef.shape = cs;
    fdef.filter.categoryBits = Vars.BIT_GROUND;
    fdef.filter.maskBits = Vars.BIT_LAYER1 | Vars.BIT_PLAYER_LAYER | Vars.BIT_LAYER3 | Vars.BIT_BATTLE;
    fdef.isSensor = false;
    body = world.createBody(bdef);
    body.createFixture(fdef).setUserData("ground");
    body.setUserData(this);
}
项目:Aftamath    文件:CamBot.java   
public void create(){
    init = true;
    bdef = new BodyDef();
    fdef = new FixtureDef();
    //hitbox
    setDirection(false);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox((rw-4)/Vars.PPM, (rh)/Vars.PPM);

    bdef.position.set(x/Vars.PPM, y/Vars.PPM);
    bdef.type = BodyType.KinematicBody;
    fdef.shape = shape;

    body = world.createBody(bdef);
    body.setUserData(this);
    fdef.filter.maskBits = (short) (layer | Vars.BIT_GROUND | Vars.BIT_BATTLE);
    fdef.filter.categoryBits = layer;
    fdef.isSensor = true;
    body.setBullet(true);
    body.createFixture(fdef).setUserData(Vars.trimNumbers(ID));
    body.setFixedRotation(true);
}
项目:Aftamath    文件:TextTrigger.java   
public void create() {
    init = true;
    PolygonShape shape = new PolygonShape();
    shape.setAsBox((rw)/Vars.PPM, (rh)/Vars.PPM);

    bdef.position.set(x/Vars.PPM, y/Vars.PPM);
    bdef.type = BodyType.KinematicBody;
    fdef.shape = shape;

    fdef.isSensor = true;
    body = world.createBody(bdef);
    body.setUserData(this);
    fdef.filter.maskBits = (short) ( Vars.BIT_GROUND | Vars.BIT_BATTLE| Vars.BIT_LAYER1| Vars.BIT_PLAYER_LAYER| Vars.BIT_LAYER3);
    fdef.filter.categoryBits = (short) ( Vars.BIT_GROUND | Vars.BIT_BATTLE| Vars.BIT_LAYER1| Vars.BIT_PLAYER_LAYER| Vars.BIT_LAYER3);
    body.createFixture(fdef).setUserData(Vars.trimNumbers(ID));
}
项目:Aftamath    文件:EventTrigger.java   
public void create() {
    PolygonShape shape = new PolygonShape();
    shape.setAsBox((width/2-2)/Vars.PPM, (height/2)/Vars.PPM);

    bdef.position.set(x/Vars.PPM, y/Vars.PPM);
    bdef.type = BodyType.KinematicBody;
    fdef.shape = shape;

    fdef.isSensor = true;
    if(world==null) world = main.getWorld();
    body = world.createBody(bdef);
    body.setUserData(this);
    fdef.filter.maskBits = (short) ( Vars.BIT_GROUND | Vars.BIT_BATTLE| Vars.BIT_LAYER1| Vars.BIT_PLAYER_LAYER| Vars.BIT_LAYER3);
    fdef.filter.categoryBits = (short) ( Vars.BIT_GROUND | Vars.BIT_BATTLE| Vars.BIT_LAYER1| Vars.BIT_PLAYER_LAYER| Vars.BIT_LAYER3);
    body.createFixture(fdef).setUserData(Vars.trimNumbers("eventTrigger"));
}
项目: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();
}
项目:Pong-Tutorial    文件:Player.java   
public Player(World world, float x, float y, float width, float height) {

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.position.set(x, y);
    this.width = width;
    this.height = height;


    PolygonShape shape = new PolygonShape();
    shape.setAsBox(width, height);

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

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

    shape.dispose();
}