Java Code Examples for com.badlogic.gdx.physics.box2d.Fixture#isSensor()
The following examples show how to use
com.badlogic.gdx.physics.box2d.Fixture#isSensor() .
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: RadarSensorSystem.java From Entitas-Java with MIT License | 6 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(); if (indexEntityA != null && indexEntityB != null && tagSensorA != null && tagSensorA.equals("RadarSensor")) { GameEntity entityB = Indexed.getInteractiveEntity(indexEntityB); if (entityB != null) { for (SensorEntity entity : sensorGroup.getEntities()) { RadarSensor radar = entity.getRadarSensor(); if (entityB.getTags().values.contains(radar.targetTag)) { if (collisionSignal) { Indexed.addEntityInSensor(entity, entityB); } else { Indexed.removeEntityInSensor(entity, entityB); } radar.collisionSignal = collisionSignal; } } } } } }
Example 2
Source File: DebugRenderer.java From tilt-game-android with MIT License | 6 votes |
/** * Translates b2d Fixture to appropriate color, depending on body state/type * Modify to suit your needs * @param fixture * @return */ private static Color fixtureToColor(Fixture fixture) { if (fixture.isSensor()) { return Color.PINK; } else { Body body = fixture.getBody(); if (!body.isActive()) { return Color.BLACK; } else { if (!body.isAwake()) { return Color.RED; } else { switch (body.getType()) { case StaticBody: return Color.CYAN; case KinematicBody: return Color.WHITE; case DynamicBody: default: return Color.GREEN; } } } } }
Example 3
Source File: BuoyancySample.java From Codelabs with MIT License | 5 votes |
@Override public void beginContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); if (fixtureA.isSensor() && fixtureB.getBody().getType() == BodyType.DynamicBody) { buoyancyController.addBody(fixtureB); } else if (fixtureB.isSensor() && fixtureA.getBody().getType() == BodyType.DynamicBody) { buoyancyController.addBody(fixtureA); } }
Example 4
Source File: BuoyancySample.java From Codelabs with MIT License | 5 votes |
@Override public void endContact(Contact contact) { Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); if (fixtureA.isSensor() && fixtureB.getBody().getType() == BodyType.DynamicBody) { buoyancyController.removeBody(fixtureB); } else if (fixtureB.isSensor() && fixtureA.getBody().getType() == BodyType.DynamicBody) { if (fixtureA.getBody().getWorldCenter().y > -1) { buoyancyController.removeBody(fixtureA); } } }
Example 5
Source File: FluidSimulatorGeneric.java From fluid-simulator-v2 with Apache License 2.0 | 5 votes |
@Override public boolean reportFixture (Fixture fixture) { if (fixture.getBody().getType() != BodyType.StaticBody && !fixture.isSensor() && ((ObjectInfo)fixture.getBody().getUserData()).isPortalAllowed) { // Prevent portal looping if (!((ObjectInfo)fixture.getBody().getUserData()).hasTimePassed(300)) return true; for (int i=0; i<portalIn.size(); i++) { if (portalIn.get(i).fixture.testPoint(fixture.getBody().getPosition().x, fixture.getBody().getPosition().y)) { logicHitBody = fixture.getBody(); if (logicHitBody != null) { logicHitBody.setTransform(portalOut.get(i).getBody().getPosition(), 0); if (portalOut.get(i).normal != null) { // New velocity angle //System.out.println("vel: "+logicHitBody.getLinearVelocity().angle()+" norm: " + portalOut.get(i).normal.angle()+" angle: " + portalOut.get(i).angle); logicHitBody.setLinearVelocity(logicHitBody.getLinearVelocity().rotate(portalOut.get(i).angle - logicHitBody.getLinearVelocity().angle())); // Apply a little more linear force if (allowPortalTransferForce) logicHitBody.applyForceToCenter(portalOut.get(i).transferForce, true); } if (fixture.getBody().getUserData() != null) ((ObjectInfo)fixture.getBody().getUserData()).updateTime(); // handlePortalCallbackRendering(portalIn.get(i).getBody().getPosition(), portalOut.get(i).getBody().getPosition()); } } } } return true; }
Example 6
Source File: FluidSimulatorGeneric.java From fluid-simulator-v2 with Apache License 2.0 | 5 votes |
@Override public boolean reportFixture (Fixture fixture) { if (fixture.getBody().getType() != BodyType.StaticBody && !fixture.isSensor() && ((ObjectInfo)fixture.getBody().getUserData()).isPortalAllowed) { // Prevent portal looping if (!((ObjectInfo)fixture.getBody().getUserData()).hasTimePassed(300)) return true; for (int i=0; i<portalIn.size(); i++) { if (portalOut.get(i).fixture.testPoint(fixture.getBody().getPosition().x, fixture.getBody().getPosition().y)) { logicHitBody = fixture.getBody(); if (logicHitBody != null) { logicHitBody.setTransform(portalIn.get(i).getBody().getPosition(), 0); if (portalIn.get(i).normal != null) { // New velocity angle logicHitBody.setLinearVelocity(logicHitBody.getLinearVelocity().rotate(portalIn.get(i).normal.angle() - logicHitBody.getLinearVelocity().angle())); // Apply a little more linear force if (allowPortalTransferForce) logicHitBody.applyForceToCenter(portalIn.get(i).transferForce, true); } if (fixture.getBody().getUserData() != null) ((ObjectInfo)fixture.getBody().getUserData()).updateTime(); // handlePortalCallbackRendering(portalOut.get(i).getBody().getPosition(), portalIn.get(i).getBody().getPosition()); } } } } return true; }
Example 7
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); } } } } } } } } }