I’m using AndEngine and I adopted a Component-Entity Model to developing my game. My question is in an AndEngine setup, where and how should I invoke the update methods of my entities (and their components)?
I’ve only started using AndEngine two days ago, so forgive me for any noobity.
In AndEngine, for your Entity to have an update method that gets invoked at every frame, its class must implement the
IUpdateHandlerinterface.This will force you to override the
public void onUpdate(float pSecondsElapsed)andpublic void reset()methods.You then place your “update code” in the body of
onUpdate(float pSecondsElapsed).The instantiated object implementing the
IUpdateHandlerinterface then must be registered in yourSceneobject via theregisterUpdateHandler(IUpdateHandler updateHandler).Here’s an example code:
Entity class with the update method.
And then in the initialization block of your
SimpleBaseGameActivitywhere you have the main scene declared asYou register the Entity like this: