@Override public boolean reportFixture (Fixture fixture) { // if the hit fixture's body is the ground body // we ignore it if (fixture.getBody() == groundBody) return true; // if the hit point is inside the fixture of the body // we report it if (fixture.testPoint(testPoint.x, testPoint.y)) { hitBody = fixture.getBody(); return false; } else return true; } };
@Override public boolean shouldCollide (Fixture fixtureA, Fixture fixtureB) { if ((fixtureA == m_platform && fixtureB == m_character) || (fixtureB == m_platform && fixtureA == m_character)) { Vector2 position = m_character.getBody().getPosition(); if (position.y < m_top + m_radius - 3.0f * 0.005f) return false; else return true; } else return true; }
@Override public boolean reportFixture (Fixture fixture) { // if the hit point is inside the fixture of the body // we report it if (fixture.testPoint(testPoint.x, testPoint.y)) { hitBody = fixture.getBody(); return false; } else return true; } };
@Override public void beginContact (Contact contact) { System.out.println(String.format("beginContact() addr=%d", getContactAddr(contact))); System.out.println(String.format("beginContact() addrA=%d, addrB=%d", getFixtureAddrA(contact), getFixtureAddrB(contact))); System.out.println(String.format("beginContact() fixA=%s, fixB=%s", contact.getFixtureA(), contact.getFixtureB())); final Body toRemove = contact.getFixtureA().getBody().getType() == BodyType.DynamicBody ? contact.getFixtureA().getBody() : contact.getFixtureB().getBody(); Gdx.app.postRunnable(new Runnable() { @Override public void run () { world.destroyBody(toRemove); } }); }
private void drawContact (Contact contact) { WorldManifold worldManifold = contact.getWorldManifold(); if (worldManifold.getNumberOfContactPoints() == 0) return; Vector2 point = worldManifold.getPoints()[0]; renderer.setColor(getColorByBody(contact.getFixtureA().getBody())); renderer.point(point.x, point.y, 0); }
private boolean isPlayerGrounded (float deltaTime) { groundedPlatform = null; Array<Contact> contactList = world.getContactList(); for (int i = 0; i < contactList.size; i++) { Contact contact = contactList.get(i); if (contact.isTouching() && (contact.getFixtureA() == playerSensorFixture || contact.getFixtureB() == playerSensorFixture)) { Vector2 pos = player.getPosition(); WorldManifold manifold = contact.getWorldManifold(); boolean below = true; for (int j = 0; j < manifold.getNumberOfContactPoints(); j++) { below &= (manifold.getPoints()[j].y < pos.y - 1.5f); } if (below) { if (contact.getFixtureA().getUserData() != null && contact.getFixtureA().getUserData().equals("p")) { groundedPlatform = (Platform)contact.getFixtureA().getBody().getUserData(); } if (contact.getFixtureB().getUserData() != null && contact.getFixtureB().getUserData().equals("p")) { groundedPlatform = (Platform)contact.getFixtureB().getBody().getUserData(); } return true; } return false; } } return false; }
@Override public boolean reportFixture(Fixture fixture) { body = fixture.getBody(); return false; }
@Override public boolean reportFixture (Fixture fixture) { // if the hit fixture's body is the ground body // we ignore it if (fixture.getBody() == fixBody) return true; // if the hit point is inside the fixture of the body // we report it if (fixture.testPoint(testPoint.x, testPoint.y)) { hitBody = fixture.getBody(); return false; } else return true; } };
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (fixture.getBody() == body) { return 1; } if (fraction < 1.0f && fixture.getFilterData().categoryBits == GameManager.BOMB_BIT) { hitting = true; } return 0; } };
@Override public boolean reportFixture (Fixture fixture) { // if the hit point is inside the fixture of the body // we report it if (fixture.testPoint(point.x, point.y)) { hitBody = fixture.getBody(); return false; } else return true; } };
@Override public boolean reportFixture (Fixture fixture) { // if the hit point is inside the fixture of the body // we report it if (fixture.testPoint(point.x, point.y)) { hitBody = fixture.getBody(); return false; } else return true; } };
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (fixture.getBody() == body) { return 1; } if (fraction < 1.0f && fixture.getFilterData().categoryBits == GameManager.BOMB_BIT) { hitting = true; } return 0; } };
@Override public void beginContact(Contact contact) { // TODO Auto-generated method stub Fixture fixtureA = contact.getFixtureA(); Fixture fixtureB = contact.getFixtureB(); Body bodyA = fixtureA.getBody(); Body bodyB = fixtureB.getBody(); if(bodyA == pointerBody && bodyB != groundBody) bodyB.setUserData(true); else if(bodyB == pointerBody && bodyA != groundBody) bodyA.setUserData(true); }
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { // Print contact info Gdx.app.log(TAG, " Contact!! " + fixture.getBody().getUserData() + " at [" + point.x + ";" + point.y + "]"); return -1; // Continue with the rest of the fixtures } };
public void beginContact(Contact c) { Body b = c.getFixtureA().getBody(); Image i = (Image) blocks.get(b); if (i != null) { i.remove(); } else if (b == floorBody) { show(); } } public void endContact(Contact c) {}
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (fixture.getFilterData().categoryBits == GameManager.BOMB_BIT) { Entity bombEntity = (Entity) fixture.getBody().getUserData(); kickingBomb = bombEntity.getComponent(Bomb.class); return 0; } return 0; } };
@Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { collision.set(point); Box2DQuerySample.this.normal.set(normal).add(point); // Show contact info title = fixture.getBody().getUserData() + " at [" + point.x + ";" + point.y + "]"; layout.setText(font, title); titleWidth = layout.width * 0.5f; return 1; // Continue with the rest of the fixtures } };
@Override public void beginContact(Contact contact) { Body a = contact.getFixtureA().getBody(); Body b = contact.getFixtureB().getBody(); if ((BodyUtils.bodyIsRunner(a) && BodyUtils.bodyIsEnemy(b)) || (BodyUtils.bodyIsEnemy(a) && BodyUtils.bodyIsRunner(b))) { runner.hit(); } else if ((BodyUtils.bodyIsRunner(a) && BodyUtils.bodyIsGround(b)) || (BodyUtils.bodyIsGround(a) && BodyUtils.bodyIsRunner(b))) { runner.landed(); } }
private void drawContact (Contact contact) { WorldManifold worldManifold = contact.getWorldManifold(); if (worldManifold.getNumberOfContactPoints() == 0) return; Vector2 point = worldManifold.getPoints()[0]; renderer.setColor(getColorByBody(contact.getFixtureA().getBody())); renderer.point(point.x, point.y, 0); }