List of usage examples for com.badlogic.gdx.physics.box2d Body getWorld
public World getWorld()
From source file:com.sertaogames.cactus2d.components.TileMapPhysics.java
License:Open Source License
@Override public void destroy() { for (Body rigidbody : bodies) { rigidbody.getWorld().destroyBody(rigidbody); } }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java
License:Apache License
/** clones a {@link Body} * @param body the {@link Body} to copy * @param shapes if the {@link Shape Shapes} of the {@link Fixture Fixures} of the given {@code body} should be {@link #clone(Shape) copied} as well * @return a deep copy of the given {@code body} */ public static Body clone(Body body, boolean shapes) { Body clone = body.getWorld().createBody(createDef(body)); clone.setUserData(body.getUserData()); for (Fixture fixture : body.getFixtureList()) clone(fixture, clone, shapes);/*from w ww . j ava 2 s. co m*/ return clone; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DUtils.java
License:Apache License
/** @param body the Body to split * @param a the first point of the segment * @param b the second point of the segment * @param store The {@link Pair} to store the resulting bodies in. May be null. * @return If the body was successfully split, which means that all fixtures intersecting with the given segment were split. If false, only some fixtures may have been created! */ public static boolean split(Body body, Vector2 a, Vector2 b, Pair<Body, Body> store) { World world = body.getWorld(); BodyDef bodyDef = createDef(body);/* w ww .jav a 2s .co m*/ Body aBody = world.createBody(bodyDef), bBody = world.createBody(bodyDef); for (Fixture fixture : body.getFixtureList()) if (!split(fixture, a, b, aBody, bBody, null)) return false; if (store != null) store.set(aBody, bBody); return true; }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Chain.java
License:Apache License
/** @param index the index of the {@link #segments segment} to {@link World#destroyBody(Body) destroy} * @see #remove(int) *//* w w w .j a va 2s . c o m*/ public void destroy(int index) { Body segment = remove(index); segment.getWorld().destroyBody(segment); }
From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Chain.java
License:Apache License
/** {@link #destroy(int) destroys} all segments from beginIndex to endIndex * @param beginIndex the first index to destroy * @param endIndex the last index to destroy */ public void destroy(int beginIndex, int endIndex) { Array<Body> removed = remove(beginIndex, endIndex); for (Body body : removed) body.getWorld().destroyBody(body); removed.clear();//from ww w. j a v a2 s. co m }
From source file:net.dermetfan.utils.libgdx.box2d.Box2DUtils.java
License:Apache License
/** creates a deep copy of a {@link Body} * @param body the {@link Body} to copy * @param shapes if the {@link Shape Shapes} of the {@link Fixture Fixures} of the given {@code body} should be {@link #copy(Shape) copied} as well * @return a deep copy of the given {@code body} */ public static Body copy(Body body, boolean shapes) { BodyDef bodyDef = new BodyDef(); bodyDef.active = body.isActive();// ww w .j ava 2 s. co m bodyDef.allowSleep = body.isSleepingAllowed(); bodyDef.angle = body.getAngle(); bodyDef.angularDamping = body.getAngularDamping(); bodyDef.angularVelocity = body.getAngularVelocity(); bodyDef.awake = body.isAwake(); bodyDef.bullet = body.isBullet(); bodyDef.fixedRotation = body.isFixedRotation(); bodyDef.gravityScale = body.getGravityScale(); bodyDef.linearDamping = body.getLinearDamping(); bodyDef.linearVelocity.set(body.getLinearVelocity()); bodyDef.position.set(body.getPosition()); bodyDef.type = body.getType(); Body copy = body.getWorld().createBody(bodyDef); copy.setUserData(body.getUserData()); for (Fixture fixture : body.getFixtureList()) copy(fixture, copy, shapes); return copy; }