/** Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. * This will automatically adjust the mass of the body if the body is dynamic and the fixture has positive density. All * fixtures attached to a body are implicitly destroyed when the body is destroyed. * @param fixture the fixture to be removed. * @warning This function is locked during callbacks. */ public void destroyFixture (Fixture fixture) { this.world.destroyFixture(this, fixture); fixture.setUserData(null); this.world.fixtures.remove(fixture.addr); this.fixtures.removeValue(fixture, true); this.world.freeFixtures.free(fixture); }
public MovingPlatform (float x, float y, float width, float height, float dx, float dy, float da, float maxDist) { platform = createBox(BodyType.KinematicBody, width, height, 1); pos.x = x; pos.y = y; dir.x = dx; dir.y = dy; this.maxDist = maxDist; platform.setTransform(pos, 0); platform.getFixtureList().get(0).setUserData("p"); platform.setAngularVelocity(da); platform.setUserData(this); }
public CirclePlatform (int x, int y, float radius, float da) { platform = createCircle(BodyType.KinematicBody, radius, 1); platform.setTransform(x, y, 0); platform.getFixtureList().get(0).setUserData("p"); platform.setAngularVelocity(da); platform.setUserData(this); }
/** Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during * callbacks. * @warning This automatically deletes all associated shapes and joints. * @warning This function is locked during callbacks. */ public void destroyBody (Body body) { Array<JointEdge> jointList = body.getJointList(); while (jointList.size > 0) destroyJoint(body.getJointList().get(0).joint); jniDestroyBody(addr, body.addr); body.setUserData(null); this.bodies.remove(body.addr); Array<Fixture> fixtureList = body.getFixtureList(); while(fixtureList.size > 0) { Fixture fixtureToDelete = fixtureList.removeIndex(0); this.fixtures.remove(fixtureToDelete.addr).setUserData(null); freeFixtures.free(fixtureToDelete); } freeBodies.free(body); }
public Brick(PlayScreen screen, MapObject object){ super(screen, object); fixture.setUserData(this); setCategoryFilter(MarioBros.BRICK_BIT); }
public Coin(PlayScreen screen, MapObject object){ super(screen, object); tileSet = map.getTileSets().getTileSet("tileset_gutter"); fixture.setUserData(this); setCategoryFilter(MarioBros.COIN_BIT); }
/** Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. * This will automatically adjust the mass of the body if the body is dynamic and the fixture has positive density. All * fixtures attached to a body are implicitly destroyed when the body is destroyed. * @param fixture the fixture to be removed. * @warning This function is locked during callbacks. */ public void destroyFixture (Fixture fixture) { this.world.destroyFixture(this, fixture); fixture.setUserData(null); this.world.fixtures.remove(fixture.addr); this.fixtures.removeValue(fixture, true); this.world.freeFixtures.free(fixture); }
fd.shape = shape; Fixture f = body.createFixture(fd); f.setUserData(userData);
public void defineMario(){ BodyDef bdef = new BodyDef(); bdef.position.set(32 / 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.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT | MarioBros.ITEM_BIT; fdef.shape = shape; b2body.createFixture(fdef).setUserData(this); EdgeShape head = new EdgeShape(); head.set(new Vector2(-2 / MarioBros.PPM, 6 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 6 / MarioBros.PPM)); fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT; fdef.shape = head; fdef.isSensor = true; b2body.createFixture(fdef).setUserData(this); }
public void defineBigMario(){ Vector2 currentPosition = b2body.getPosition(); world.destroyBody(b2body); BodyDef bdef = new BodyDef(); bdef.position.set(currentPosition.add(0, 10 / 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.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT | MarioBros.ITEM_BIT; fdef.shape = shape; b2body.createFixture(fdef).setUserData(this); shape.setPosition(new Vector2(0, -14 / MarioBros.PPM)); b2body.createFixture(fdef).setUserData(this); EdgeShape head = new EdgeShape(); head.set(new Vector2(-2 / MarioBros.PPM, 6 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 6 / MarioBros.PPM)); fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT; fdef.shape = head; fdef.isSensor = true; b2body.createFixture(fdef).setUserData(this); timeToDefineBigMario = false; }
public void redefineMario(){ Vector2 position = b2body.getPosition(); world.destroyBody(b2body); BodyDef bdef = new BodyDef(); bdef.position.set(position); 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.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT | MarioBros.ENEMY_HEAD_BIT | MarioBros.ITEM_BIT; fdef.shape = shape; b2body.createFixture(fdef).setUserData(this); EdgeShape head = new EdgeShape(); head.set(new Vector2(-2 / MarioBros.PPM, 6 / MarioBros.PPM), new Vector2(2 / MarioBros.PPM, 6 / MarioBros.PPM)); fdef.filter.categoryBits = MarioBros.MARIO_HEAD_BIT; fdef.shape = head; fdef.isSensor = true; b2body.createFixture(fdef).setUserData(this); timeToRedefineMario = false; }
@Override public void defineItem() { BodyDef bdef = new BodyDef(); bdef.position.set(getX(), getY()); bdef.type = BodyDef.BodyType.DynamicBody; body = 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; fdef.shape = shape; body.createFixture(fdef).setUserData(this); }
/** Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during * callbacks. * @warning This automatically deletes all associated shapes and joints. * @warning This function is locked during callbacks. */ public void destroyBody (Body body) { Array<JointEdge> jointList = body.getJointList(); while (jointList.size > 0) destroyJoint(body.getJointList().get(0).joint); jniDestroyBody(addr, body.addr); body.setUserData(null); this.bodies.remove(body.addr); Array<Fixture> fixtureList = body.getFixtureList(); while(fixtureList.size > 0) { Fixture fixtureToDelete = fixtureList.removeIndex(0); this.fixtures.remove(fixtureToDelete.addr).setUserData(null); freeFixtures.free(fixtureToDelete); } freeBodies.free(body); }
b2body.createFixture(fdef).setUserData(this); fdef.restitution = 0.5f; fdef.filter.categoryBits = MarioBros.ENEMY_HEAD_BIT; b2body.createFixture(fdef).setUserData(this);
b2body.createFixture(fdef).setUserData(this); fdef.restitution = 1.8f; fdef.filter.categoryBits = MarioBros.ENEMY_HEAD_BIT; b2body.createFixture(fdef).setUserData(this);
public void defineFireBall(){ BodyDef bdef = new BodyDef(); bdef.position.set(fireRight ? getX() + 12 /MarioBros.PPM : getX() - 12 /MarioBros.PPM, getY()); bdef.type = BodyDef.BodyType.DynamicBody; if(!world.isLocked()) b2body = world.createBody(bdef); FixtureDef fdef = new FixtureDef(); CircleShape shape = new CircleShape(); shape.setRadius(3 / MarioBros.PPM); fdef.filter.categoryBits = MarioBros.FIREBALL_BIT; fdef.filter.maskBits = MarioBros.GROUND_BIT | MarioBros.COIN_BIT | MarioBros.BRICK_BIT | MarioBros.ENEMY_BIT | MarioBros.OBJECT_BIT; fdef.shape = shape; fdef.restitution = 1; fdef.friction = 0; b2body.createFixture(fdef).setUserData(this); b2body.setLinearVelocity(new Vector2(fireRight ? 2 : -2, 2.5f)); }
Array<Fixture> fs = body.getFixtureList(); for (Fixture f : fs) { f.setUserData(carType);