Ignoring entity updates
One of the most important rules for game development when it comes to optimizing a game is, don't do work that does not need to be done!. In this recipe, we're going to talk about how we can use the setIgnoreUpdate()
method on our entities in order to restrict the update thread to only update what should be updated, rather than constantly updating all of our entities whether we're using them or not.
How to do it…
The following setIgnoreUpdate(boolean)
methods allow us to control which entities will be updated via the engine's update thread:
Entity entity = new Entity(); // Ignore updates for this entity entity.setIgnoreUpdate(true); // Allow this entity to continue updating entity.setIgnoreUpdate(false);
How it works…
As we've discussed in the previous chapters, each child's onUpdate()
method is called via its parent. The engine first updates, calling the update method for the main Scene
object. The scene then proceeds to call all of the update methods...