Using update handlers with conditionals
To reduce the performance cost of running an update handler with heavy calculations, we can include a conditional statement that tells the update handler to run a specific set of instructions over another. For instance, if we have enemies that check to see if the player is within their sight, we can choose to let the vision calculations run only once every three updates. In this recipe, we will demonstrate a simple conditional statement that switches between a performance-intensive calculation and a very simple calculation by touching the screen.
Getting ready...
Create a new class named UpdateHandlersAndConditionalsActivity
that extends BaseGameActivity
and implements IOnSceneTouchListener
. We will use this class to demonstrate how to use conditional statements with an update handler.
How to do it...
Follow these steps to create an update handler that uses a conditional block to determine which code to run:
Place the following definitions in the new class...