Java Code Examples for com.badlogic.gdx.physics.box2d.Body#resetMassData()
The following examples show how to use
com.badlogic.gdx.physics.box2d.Body#resetMassData() .
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 | 6 votes |
public static Body createEnemy(World world) { EnemyType enemyType = RandomUtils.getRandomEnemyType(); BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.KinematicBody; bodyDef.position.set(new Vector2(enemyType.getX(), enemyType.getY())); PolygonShape shape = new PolygonShape(); shape.setAsBox(enemyType.getWidth() / 2, enemyType.getHeight() / 2); Body body = world.createBody(bodyDef); body.createFixture(shape, enemyType.getDensity()); body.resetMassData(); EnemyUserData userData = new EnemyUserData(enemyType.getWidth(), enemyType.getHeight(), enemyType.getAnimationAssetId()); body.setUserData(userData); shape.dispose(); return body; }
Example 2
Source File: Ball.java From homescreenarcade with GNU General Public License v3.0 | 5 votes |
public static Ball create(World world, float x, float y, float radius, Color primaryColor, Color secondaryColor) { Body ballBody = Box2DFactory.createCircle(world, x, y, radius, false); ballBody.setBullet(true); // Default is radius of 0.5, if different we want the mass to be the same (could be // configurable if needed), so adjust density proportional to square of the radius. if (radius != 0.5f) { ballBody.getFixtureList().get(0).setDensity((0.5f*0.5f) / (radius*radius)); ballBody.resetMassData(); } return new Ball(ballBody, primaryColor, secondaryColor); }
Example 3
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 4
Source File: NinjaRabbitBodyFactory.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
@Override public Body create(final World world, final BodyDef definition, final Direction direction) { Body rabbitBody = world.createBody(definition); loader.attachFixture(rabbitBody, RABBIT_IDENTIFIER + "-" + direction.direction(), fdef, NINJA_RABBIT_SCALE); Fixture footSensor = rabbitBody.getFixtureList().get(FOOT_FIXTURE_INDEX); footSensor.setUserData(NinjaRabbitPhysicsProcessor.FOOT_IDENTIFIER); footSensor.setDensity(0.0f); footSensor.setSensor(true); rabbitBody.resetMassData(); return rabbitBody; }
Example 5
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); } } } } } } } } }