コード例 #1
0
ファイル: WorldUtils.java プロジェクト: caxaria/runner_bros
  public static Body createRunner(World world, float x, float y, float width, float height) {

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(new Vector2(x, y));
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(0.5f, 0.5f, new Vector2(2, 2), 45);
    Body body = world.createBody(bodyDef);

    body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE);
    Fixture fixture = body.createFixture(shape, Constants.RUNNER_DENSITY);
    body.setFixedRotation(true);
    fixture.setFriction(2f);

    body.resetMassData();
    body.setUserData(new RunnerUserData());
    shape.dispose();

    body.setBullet(true);

    return body;
  }
コード例 #2
0
ファイル: Potion.java プロジェクト: kinkoviktor/OLD-34
 private Body createBody(float x, float y, float width, float height, boolean sensor) {
   BodyDef bodyDef = new BodyDef();
   bodyDef.type = BodyDef.BodyType.KinematicBody;
   bodyDef.position.set(new Vector2(x, y));
   bodyDef.allowSleep = true;
   PolygonShape shape = new PolygonShape();
   shape.setAsBox(width / 2, height / 2, new Vector2(0, 0), 0);
   Body _body = WorldUtils.world.createBody(bodyDef);
   Fixture fixture = _body.createFixture(shape, 1.0f);
   fixture.setFriction(0);
   fixture.setSensor(sensor);
   if (!sensor) {
     fixture.setUserData(Constants.POTION_FIXTURE);
   } else {
     fixture.setUserData(Constants.NOT_COLLIDER_FIXTURE);
   }
   Filter filter = new Filter();
   filter.categoryBits = Constants.COLLISION_CREATURE;
   filter.maskBits =
       Constants.COLLISION_GROUND + Constants.COLLISION_CREATURE + Constants.COLLISION_FIELD;
   fixture.setFilterData(filter);
   _body.setUserData(this);
   return _body;
 }