Getting started with update handlers
Update handlers are essentially portions of code that we register with either entities or the engine, that are run whenever the engine updates the scene. In most situations, this updating occurs every time a frame is drawn, regardless of whether entities or the scene have been altered. Update handlers can be a powerful means of running a game, but overusing them or performing heavy calculations in them will lead to poor performance. This recipe will cover the basics of adding a simple update handler to an activity.
Getting ready...
Create a new class named UpdateHandlersActivity
that extends BaseGameActivity
. We will use this class to create a basic update handler.
How to do it...
Follow these steps to create an update handler that displays how many updates have occurred:
Place the following definitions within our
UpdateHandlersActivity
class:public static int cameraWidth = 800; public static int cameraHeight = 480; public Scene mScene;public Font fontDefault32Bold...