AndEngine confusion unregistering IUpdateHandler
My apologies if this question is a little new. I am using AndEngine and my question is specific to this framework. Suppose I create an IUpdateHandler like this:
this.registerUpdateHandler(new IUpdateHandler() {
@Override
public void onUpdate(float pSecondsElapsed) {
doUpdate(pSecondsElapsed);
}
@Override
public void reset() {
// TODO Auto-generated method stub
}
});
In my doUpdate () method, I have information that I need at some point in order to determine that it's time to unregister the IUpdateHandler. There's an unRegisterUpdateHandler () method that sounds perfect for this purpose, but to use it I need to pass some reference to the update handler and I don't have such a reference. What am I missing?
source to share
The code you provided creates an anonymous instance IUpdateHandler
that you don't have a link to. Instead, you must first store the created one IUpdateHandler
in some variable, for example IUpdateHandler myHandler = new IUpdateHandler() {...});
, and then register it with this.registerUpdateHandler(myHandler)
. With a link to the handler, you can unregister using the method you specified.
source to share
If you are inside an update handler, you can undo it. If your update handler is registered in the scene
this.registerUpdateHandler(new IUpdateHandler() {
@Override
public void onUpdate(float pSecondsElapsed) {
doUpdate(pSecondsElapsed);
}
@Override
public void reset() {
if (something) Scene.this.unregisterUpdateHandler(this);
}
});
source to share