Monday, 15 April 2013

java - AndEngine - Scene variables won't reset after changing the scene -



java - AndEngine - Scene variables won't reset after changing the scene -

here scenario:

i have next scenes:

splashscene loadingscene gamemodescene playmodescene gamescene

i have scenecontroller class manages navigation between scenes. in scenecontroller have instances scenes.

i'm initializing scene instances , doing loading of scene resources in loadingscene.

when alter scene gamemodescene playmodescene - works fine. but, when seek alter scene 1 time again gamemodescene boolean , other variables initialized during 1st run of gamemodescene remains , won't reset.

note : variables private each class , non-static

i tried pgamemodesceneto.reset(); won't work. anyy suggestions?

here how i'm initializing scene insatnces

scenecontroller.loadsceneresources()

public void loadsceneresources(scenetype mtype){ switch(mtype){ case splashscene: this.msplashscene = new splashscene(this.mactivity); break; case loadingscene: mloadingscene = new loadingscene(mactivity); break; case gamemodescene: mgamemodescene=new gamemodescene(this.mactivity); break; case playmodescene: mplaymodescene=new playmodescene(this.mactivity); break; case gamescene: break; default: } }

constructor of each class loading resources.

here how m getiing current scene instance

scenecontroller.getscene() public scene getscene(scenetype mtype){

switch(mtype){ case splashscene: this.mcurrentscene = msplashscene; break; case loadingscene: this.mcurrentscene = mloadingscene; break; case gamemodescene: this.mcurrentscene = mgamemodescene; break; case playmodescene: this.mcurrentscene = mplaymodescene; break; default: }

in org.andengine.entity.scene.scene class, there's reset() method, assume you're referring when

i tried pgamemodesceneto.reset(); won't work.

all method following:

@override public void reset() { super.reset(); this.clearchildscene(); }

your scenes (i assume) extending scene. when phone call reset() on them, you're doing initializing parent-level info , up-the-tree there via super.reset() call. (scene extends entity.) none of private fields create , set in scene affected this. behavior want, override reset() method in individual scene classes. create sure phone call super.reset() @ start of them , add together initializing information, i.e., whatever "empty" scene should like. this:

@override public void reset() { super.reset(); mylocalint = 0; mylocalfancypantsobject = null; }

java android variables andengine scene

No comments:

Post a Comment