Is there any way to fade in / out a spatial without affecting the rest of the scene?
Use a timed life controller and set the alpha level of the AlphaRenderingState.
public ColorRGBA color = new ColorRGBA( 1, 0, 0, 1 );
public void showLoadingGfx() {
TimedLifeController fader = new TimedLifeController( 2.5f ) {
public void updatePercentage( float percentComplete ) {
color.a = percentComplete;
}
};
rootNode.addController( fader );
fader.setActive( true );
}
public void hideLoadingGfx() {
TimedLifeController fader = new TimedLifeController( 2.5f ) {
public void updatePercentage( float percentComplete ) {
color.a = 1.0f - percentComplete;
}
};
rootNode.addController( fader );
fader.setActive( true );
}
So I'm assuming that you mean change the diffuse color for a materialstate, right? What I am trying to do is very dynamic. I'm trying to create a method which will accept a parent node and will fade everything under that parent (in / out). The parent node might not have a materialstate, but the children do. However, the children might have different alpha values which I will want to remember when I fade in after fading out. So I'm not sure which is the best way to do this – surely someone has created a fade-in/fade-out effect for entire tree of objects?
I can't create a new MaterialState and assign it to the parent node, right? Or else the children will inherit that materialstate rather than merging with it. Also, what you are referring to (I think) is TransitionGameState/LoadingGameState, which changes the alpha value of simple ortho objects like text and quads. I'm talking about full-3d objects.
What I showed you was just a snippet to get you going, if you want more precise answers ask more precise questions.
Material states are not inherited by child nodes (by default, I believe) so what I would do would be to create simple class which has a method addRootNode (start node of the Spatials you want to fade), then I would recurse through the children of each node adding them to an ArrayList of Nodes. (You could even have a method addSingleNode whose input spatial would be added to the ArrayList, for the 'odd-ball' that cannot be added to the root fade node). Then during your update loop call the class, have it iterate through the ArrayList and update the AlphaState of each node.
I don't really understand the blenderState.setconstantColor … Is it the color that stands for the alpha color ?
I have the same problem of wanting to make a node disappear. My node contains spatials with materials and others with textures.
Is there an easy way to do it or do I have to modify the alpha of each texture pixel and each material ?
Thanks for answering
Kine