/** Get the active state of the body. */ public boolean isActive () { return body.isActive(); }
assert (m_world.isLocked() == false); if (flag == isActive()) { return;
@Override public void keyPressed(char key, int argKeyCode) { switch (key) { case '1': case '2': case '3': case '4': case '5': Create(key - '1'); break; case 'a': for (int i = 0; i < k_maxBodies; i += 2) { if (m_bodies[i] != null) { boolean active = m_bodies[i].isActive(); m_bodies[i].setActive(!active); } } break; case 'd': DestroyBody(); break; } }
assert (m_world.isLocked() == false); if (flag == isActive()) { return;
@Override public void handleGameEvent(PropertyChanged aEvent) { if (!insimulation) { GameObject theChangedObject = (GameObject) aEvent.getOwner(); Set<GameObjectInstance> theChangedInstances = new HashSet<>(); for (GameObjectInstance theObjectInstance : dynamicObjects.keySet()) { if (theObjectInstance.getOwnerGameObject() == theChangedObject) { theChangedInstances.add(theObjectInstance); } } for (GameObjectInstance theObjectInstance : staticObjects.keySet()) { if (theObjectInstance.getOwnerGameObject() == theChangedObject) { theChangedInstances.add(theObjectInstance); } } for (GameObjectInstance theInstance : theChangedInstances) { Body theOldBody = gameObjectInstanceRemovedFromScene(theInstance); Body theNewBody = gameObjectInstanceAddedToScene(theInstance); if (theOldBody != null && theNewBody != null) { theNewBody.setActive(theOldBody.isActive()); } } } } }
@Override public void keyPressed(char key, int argKeyCode) { switch (key) { case '1': case '2': case '3': case '4': case '5': Create(key - '1'); break; case 'a': for (int i = 0; i < k_maxBodies; i += 2) { if (m_bodies[i] != null) { boolean active = m_bodies[i].isActive(); m_bodies[i].setActive(!active); } } break; case 'd': DestroyBody(); break; } }
builder.setAllowSleep(argBody.isSleepingAllowed()); builder.setAwake(argBody.isAwake()); builder.setActive(argBody.isActive()); builder.setFixedRotation(argBody.isFixedRotation());
assert (m_world.isLocked() == false); if (flag == isActive()) { return;
world.assertNotLocked(); if (flag == isActive()) { return;
assert (m_world.isLocked() == false); if (flag == isActive()) { return;
private void afterFrame() { insimulation = true; // Fire the queued events // Events caused by the simulation(collision) are fired after the simulation // because events might change the world, and the world is locked // while running the simulation for (GameEvent theEvent : queuedEventsOfLastLoop) { eventManager.fire(theEvent); } queuedEventsOfLastLoop.clear(); // Finally, we have to update the position of our game objects to sync them to the simulation for (Map.Entry<GameObjectInstance, Body> theEntry : dynamicObjects.entrySet()) { GameObjectInstance theObjectInstance = theEntry.getKey(); Size theInstanceSize = theObjectInstance.getOwnerGameObject().sizeProperty().get(); Body theSimulatedBody = theEntry.getValue(); Vec2 thePosition = theSimulatedBody.getPosition(); if (theSimulatedBody.isActive()) { // Now we have to use the XY coordinates again theObjectInstance.positionProperty().set( new Position((thePosition.x / SIZE_FACTOR) - theInstanceSize.width / 2, -(thePosition.y / SIZE_FACTOR) - theInstanceSize.height / 2)); theObjectInstance.rotationAngleProperty().set( Angle.fromRadians(theSimulatedBody.getAngle()).invert()); } } insimulation = false; }