Hello, i am developing a game, i am using a standard game and basicgamestates. I have a basicgamestatenode, and it has some children. When i am at menu state, i can access to a credits state (i deactivate the menustate and i active creditstate), i have developed an effect of fadeout and fadein using a timedlifecontroller. When i deactivate any state i call to fadeout function, and when any state is activated i call to fadein function. My problem is, sometimes when i active the credits state, this does not show its content, the user (me), see the fadeout menu effect, and immediately the fadein effect from menu state, not from creditstate.
This code is in menustate and it is executed when i want to access to creditsstate.
fadeAll(false, 0.7f, new Callable<Object>() {
public Object call() throws Exception {
parentGameState.deactivateChildNamed("MainMenuState");
parentGameState.activateChildNamed("CreditsMenuState");
return null;
}
});
When the creditsstate is activated this is the function that is executed:
public void setActive(boolean value) {
if (value) {
// Fade and setup inputs
fadeAll(true, 0.7f, new Callable<Object>() {
public Object call() throws Exception {
CreditsMenuState.this.setupInputs();
return null;
}
});
}
super.setActive(value);
}
I have noticed, when the problem happens the callable function is not executed.
In fadeAll function, the first argument is to define if the effect is fadein or fadeout, the second is the duration and the last is the function executed, when the effect is finished. This is the code:
public void fadeAll(final boolean mode, float timeLife,
final Callable<Object> callback) {
TimedLifeController fadeController = new TimedLifeController(timeLife) {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void updatePercentage(float percent) {
float computedValue = mode?percent:1f-percent;
CreditsMenuState.this.logoQuad.getDefaultColor().a = computedValue;
List<Spatial> devTextArray = CreditsMenuState.this.devTextNode
.getChildren();
List<Spatial> artTextArray = CreditsMenuState.this.artTextNode
.getChildren();
for (int i = 0; i < devTextArray.size(); i++) {
((Text) devTextArray.get(i)).getTextColor().a = computedValue;
}
for (int i = 0; i < artTextArray.size(); i++) {
((Text) artTextArray.get(i)).getTextColor().a = computedValue;
}
if (percent == 1f) {
try {
callback.call();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
};
this.getRootNode().addController(fadeController);
}
Thank you all.