Java Code Examples for com.badlogic.gdx.physics.box2d.CircleShape#dispose()

The following examples show how to use com.badlogic.gdx.physics.box2d.CircleShape#dispose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Box2dLightTest.java    From box2dlights with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 2
Source File: Box2dSteeringTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
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));
	}
 
Example 3
Source File: PhysicsFactory.java    From tilt-game-android with MIT License 4 votes vote down vote up
public static Body createCircleBody(final PhysicsWorld pPhysicsWorld, final float pCenterX, final float pCenterY, final float pRadius, final float pRotation, final BodyType pBodyType, final FixtureDef pFixtureDef, final float pPixelToMeterRatio) {
	final BodyDef circleBodyDef = new BodyDef();
	circleBodyDef.type = pBodyType;

	circleBodyDef.position.x = pCenterX / pPixelToMeterRatio;
	circleBodyDef.position.y = pCenterY / pPixelToMeterRatio;

	circleBodyDef.angle = MathUtils.degToRad(pRotation);

	final Body circleBody = pPhysicsWorld.createBody(circleBodyDef);

	final CircleShape circlePoly = new CircleShape();
	pFixtureDef.shape = circlePoly;

	final float radius = pRadius / pPixelToMeterRatio;
	circlePoly.setRadius(radius);

	circleBody.createFixture(pFixtureDef);

	circlePoly.dispose();

	return circleBody;
}