Time for action – display interactive status icons

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);
  }
}

What just happened?

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 ...

Get jMonkeyEngine 3.0 Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.