java - AndEngine Update -


i'm trying learn andengine , have been messing around examples. 1 modifying physicsjumpexample

what run every x seconds. have done searching , have found people suggesting:

this.scene.registerupdatehandler(new iupdatehandler() { @override public void onupdate(float psecondselapsed) {         // todo auto-generated method stub         //your code run here! } 

but find cant because of:

this.mscene.registerupdatehandler(this.mphysicsworld); 

how go running code every x seconds?

thanks in advance

you can register timer handler this:

protected scene oncreatescene() {     scene myscene = new scene();  // somewhere create scene     float xseconds = 5.5f; // meaning 5 , half second     boolean repeat = true; // true reset timer after time passed , execute again     timerhandler mytimer = new timerhandler(xseconds, repeat, new itimercallback() {         public void ontimepassed(timerhandler ptimerhandler) {             methodwithstufftodo();         }     });     myscene.registerupdatehandler(mytimer);   // here register timerhandler scene      .... // other stuff     return myscene; } 

then write in scene method implements code want execute when timer finished:

public void methodwithstufftodo(){ ... } 

explanation:

the timerhandler checked in onupdatemethod of update thread. when close indicated time (here 5.5 seconds) ontimepassed method triggered. close, because updatethread not exact last millisecod. same suggestion in code, difference timerhandler handle update method , decide when (which simpler creating one's own updatehandler).


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -