Attaching an update handler to an entity
In addition to being able to register an update handler with a Scene
object, we can register update handlers with specific entities. By registering an update handler with an entity, the handler is only called whenever the entity is attached to the engine's scene. This recipe demonstrates this process by creating an update handler, which is registered with an initially unattached entity, that increments the onscreen text.
Getting ready...
Create a new class named AttachUpdateHandlerToEntityActivity
that extends BaseGameActivity
and implements IOnSceneTouchListener
. We will use this class to attach an update handler to an Entity
object that will wait to be attached to the scene until the scene is touched.
How to do it...
Follow these steps to create an activity that demonstrates how update handlers depend on their parent entity to run:
Insert the following definitions into our new activity class:
public static int cameraWidth = 800; public static int cameraHeight...