Java Code Examples for com.badlogic.gdx.physics.box2d.Body#setGravityScale()
The following examples show how to use
com.badlogic.gdx.physics.box2d.Body#setGravityScale() .
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: WorldUtils.java From martianrun with Apache License 2.0 | 5 votes |
public static Body createRunner(World world) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set(new Vector2(Constants.RUNNER_X, Constants.RUNNER_Y)); PolygonShape shape = new PolygonShape(); shape.setAsBox(Constants.RUNNER_WIDTH / 2, Constants.RUNNER_HEIGHT / 2); Body body = world.createBody(bodyDef); body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE); body.createFixture(shape, Constants.RUNNER_DENSITY); body.resetMassData(); body.setUserData(new RunnerUserData(Constants.RUNNER_WIDTH, Constants.RUNNER_HEIGHT)); shape.dispose(); return body; }
Example 2
Source File: NearSensorSystem.java From Entitas-Java with MIT License | 4 votes |
@Override public void processCollision(Fixture colliderA, Fixture colliderB, boolean collisionSignal) { if (colliderA.isSensor() && !colliderB.isSensor()) { Integer indexEntityA = (Integer) colliderA.getBody().getUserData(); Integer indexEntityB = (Integer) colliderB.getBody().getUserData(); String tagSensorA = (String) colliderA.getUserData(); Body bodyB = colliderB.getBody(); for (Fixture fixture : bodyB.getFixtureList()) { if(fixture.isSensor()) return; } if (indexEntityA != null && indexEntityB != null && tagSensorA != null) { GameEntity entityA = Indexed.getInteractiveEntity(indexEntityA); GameEntity entityB = Indexed.getInteractiveEntity(indexEntityB); if (entityA != null && entityB != null && tagSensorA != null) { for (SensorEntity entity : sensorGroup.getEntities()) { if (entity.getLink().ownerEntity == indexEntityA) { NearSensor sensor = entity.getNearSensor(); if (sensor.targetTag != null && entityB.getTags().values.contains(sensor.targetTag)) { if (collisionSignal) { if (tagSensorA.equals("NearSensor")) { sensor.distanceContactList.add(indexEntityB); if (entity.getLink().sensorReference.contains("RadialGravity")) { bodyB.setGravityScale(0); bodyB.resetMassData(); } } else if (tagSensorA.equals("ResetNearSensor")) { sensor.resetDistanceContactList.add(indexEntityB); } } else { if (tagSensorA.equals("NearSensor")) { sensor.distanceContactList.remove(indexEntityB); if (entity.getLink().sensorReference.contains("RadialGravity")) { bodyB.setGravityScale(1); bodyB.resetMassData(); } } else if (tagSensorA.equals("ResetNearSensor")) { sensor.resetDistanceContactList.remove(indexEntityB); } } } } } } } } }