You use the SimpleUpdate()
method to calculate Vector3f.ZERO.distance(cam.getLocation())
. Depending on whether the distance is more or less than 10f, let's toggle the monkey icon between two different states: smiling and sad:
public void simpleUpdate(float tpf) { distance = Vector3f.ZERO.distance(cam.getLocation()); distanceText.setText("Distance: " + distance); if (distance < 10f) { logo.setImage(assetManager,"Interface/chimpanzee-smile.gif", true); } else { logo.setImage(assetManager, "Interface/chimpanzee-sad.gif", true); } }
You often use graphics not only as decorations but also to display game state. As shown, you can use conditional setters in the simpleUpdate()
method to keep your icons up-to-date. You create a series of icons representing game states—in this example, the states are "happy monkey" and "sad monkey". The monkey is happy when the camera is close to the origin, and sad when it...