Today thinking about develop an system i found a problem implement it…
I have one GameStateNode and some childs, the childs ever running independent of other childs.
I want that when active a GameState this start a fadeIn elements (Controller) and WHEN FINISH call to one callback, in case of fadeIn the cb is setupInputs() in case of fadeout (When we try desactive the state) the cb is deactivechildnamed…
MenuStat
IntroMenuState
MainMenuState
CreditsMenuState
My current implementation is aprox this..
In MenuState i implement a common quad, as an wood background.
i want implement that when the state START and FINNISH (active-deactive) the Geoms of the state run a FadeIn or FadeOut effect AND WHEN FADE FINISH call a method for change state (finish-case) o buildinputs events (start-case).
Then i think about implement this system:
* reimplement the setActive of each child state for DONT call the super, only assign the new GameState to this.queuedGameState attr and later call this.fadeIn() method for run controllers.
* Later in MenuState (GameStateNode) update() i check if exist fades-controllers running, and if not, look the this.queuedGameState string value for check if is same that the current active child, if is same i can confirm that the FadeIn just finish, or if this.queuedGameState is diferent string and i dont have fade controllers running, i assume that fadeOut just finish and then call the true activechild() (super)
I think that my system is tooo complex (And hardy of understand yes..) ... really i dont like, i want know if you think other way for implement better this?
It can take anywhere from 5-15 mins to setup a project like that to run here, a single class can be copy and pasted in a matter of seconds. (that really adds up when there are so many posts a day…)
It should only take around 100-200 lines to represent any problem (any more than that and the problem should be narrowed down some more)…
This is for your benefit also, I can't count the number of times I have solved my own issues by creating a simple test case.
This is for your benefit also, I can't count the number of times I have solved my own issues by creating a simple test case.
We call this a "cardboard cutout moment" in my office. One of the guys I used to work with had a small teddy bear sat next to his monitor. Sometimes when he got stuck on a problem, he tried to explain the problem to the bear (yup - barking mad I know) - but often in the case of trying to explain it clearly the solution came.
We didn't want to call this the "taking to a stuffed toy moment", so came up with a slightly less embarasing name :D
/*
* LAUNCH THE GAME
*/
GameStateTest.game = new StandardGame("StandardGame");
GameStateTest.game.getSettings().setWidth(400);
GameStateTest.game.getSettings().setHeight(200);
I read about transitionGameState but dont fix my problem. (no? im not sure)
I try make a fade alpha of all elements in current BasicGameState, and later finish the fade, call the deactive and active for change to the next gamestate.
this its possible with TransitionGameState?
Now in my code im using this code for when active the state:
public void setActive(boolean value) {
if (value) {
// Fade and setup inputs
this.fadeAll(true, 0.7f, new Callable<Object>() {
@Override
public Object call() throws Exception {
// TODO: Active inputs here
return null;
}
});
}
super.setActive(value);
}
And this other for when go out in key events.
this.fadeAll(false, 0.7f, new Callable<Object>() {
@Override
public Object call() throws Exception {
parentGameState.deactivateChildNamed("MainMenuState");
parentGameState.activateChildNamed("CreditsMenuState");
return null;
}
})
My this.fadeAll method, launch a LifedTimeController and iter over each Geom for change getDefaultColor.a attr.
Now i need implement this method new in each state. Exist the chance of change alpha of ALL gamestate.?
Update: I want make this fade effect! im doing this now with the previus code. (Its better and possible use TransitionGameState?)
VIDEO DEMO: http://www.youtube.com/watch?v=9KWeii4zMVQ
I try use TransitionGameState, with the same background image of the other gamestates background, then i think that can run fine… but…
TransitionGameState dont work fine because the "first fade" dont show the fade, jump directly to TransitionGameState image opaque and later start fadin out good.
Here i post the two gamestates the first and the second, in first GameState (update()) i launch the transition.
MyFirstGameState.java
public class MyFirstGameState extends BasicGameState {
Anyway you can whip that up into a small test (self contained, using internal classes) that someone (like myself) can just copy/paste and run? (I am no understanding the issue at hand…)
In this case it is the order in which you are adding the states (the second state needs to be added first, otherwise when activated the first game state fades out 'underneath' it…)
I have altered your test (and created a 'fade-in/fade-out' transition for you).
But for why create a new Transition class? the javadoc say:
TransitionGameState The transition game state provides additional functionality to LoadingGameState. A background image is now shown during the loading phase of LoadingGameState. In addition, if a lead in game state is provided, the transition state will fade frame the previous game state into the loading state and then fade away. The lead in game state will be deactivated once the transition is complete, but not removed from the game state manager.
Then… TransitionGameState make fadein-fadeout feature, out of box, no?
The problem is that you are never updating the progress, when the progress gets to 1.0 (through the setProgress() method) it triggers the fade out (not sure that's appropriate)…