Hi, i'm trying to do an effect on my game, i want a logo (logo.png) appears from the shadow (change the alpha from 0 to 1) gradually, but i can't, here i post my code, what could be the problem, thanks.
package gamestates;
import com.jme.image.Texture;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Text;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.MaterialState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import com.jmex.game.state.BasicGameState;
public class IntroState extends BasicGameState {
private Quad bckgQuad;
private Quad logoQuad;
private Text txtObj;
private BlendState blendState;
private int indice=0;
public String[] presenta = {"", "P", "Pr", "Pre", "Pres", "Prese", "Presen", "Present", "Presenta", "Presenta:"};
//public DefColorFadeController fader;
private MaterialState materialState;
private BlendState alphaState;
private float opacityAmount = 1.0f;
private float step = -0.5f;
public IntroState() {
super("introState");
//Create RenderStates
blendState = CreateBlendState();
materialState = CreateMaterialState();
//Create objects
bckgQuad = CreateBackGround();
logoQuad = CreateLogo();
txtObj = CreatePresenta();
getRootNode().attachChild(bckgQuad);
getRootNode().attachChild(txtObj);
bckgQuad.setRenderState(blendState);
txtObj.setRenderState(blendState);
getRootNode().setRenderQueueMode(Renderer.QUEUE_ORTHO);
logoQuad.setRenderState(materialState);
logoQuad.updateRenderState();
getRootNode().attachChild(logoQuad);
alphaState = CreateBlendState_LogoQuad();
logoQuad.setRenderState(alphaState);
logoQuad.updateRenderState();
logoQuad.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
getRootNode().updateRenderState();
}
private BlendState CreateBlendState(){
//Create BlendState
BlendState bs;
bs = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
bs.setBlendEnabled(true);
bs.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
bs.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
bs.setTestEnabled(true);
return bs;
}
private MaterialState CreateMaterialState(){
//Create MaterialState
MaterialState matState;
matState = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
matState.setAmbient(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
matState.setDiffuse(new ColorRGBA(0.1f, 0.5f, 0.8f, opacityAmount));
matState.setSpecular(new ColorRGBA(1.0f, 1.0f, 1.0f, opacityAmount));
matState.setShininess(128.0f);
matState.setEmissive(new ColorRGBA(0.0f, 0.0f, 0.0f, opacityAmount));
matState.setEnabled(true);
matState.setMaterialFace(MaterialState.MaterialFace.FrontAndBack);
return matState;
}
private BlendState CreateBlendState_LogoQuad(){
BlendState aState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
aState.setBlendEnabled(true);
aState.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
aState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
aState.setTestEnabled(true);
aState.setTestFunction(BlendState.TestFunction.GreaterThan);
aState.setEnabled(true);
return aState;
}
private Quad CreateBackGround() {
// Create background
Quad bckg;
Texture t = TextureManager.loadTexture(
IntroState.class.getClassLoader().getResource("res/woodBckg.png"),
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear);
bckg = new Quad("bckg", 1024, 768);
TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
ts.setTexture(t);
bckg.setRenderState(ts);
bckg.setLocalTranslation(512, 300, 0);
return bckg;
}
private Quad CreateLogo(){
// Create logo
Quad logo;
Texture r = TextureManager.loadTexture(
IntroState.class.getClassLoader().getResource("res/logoDarte.png"),
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear);
logo = new Quad("logo", 800, 245);
TextureState rs = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
rs.setTexture(r);
logo.setRenderState(rs);
logo.setLocalTranslation(512, 300, 0);
return logo;
}
private Text CreatePresenta(){
// Create presenta
TextureState tsFont;
Text text;
tsFont = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
tsFont.setTexture(TextureManager.loadTexture(
CreditsState.class.getClassLoader().getResource("res/gameFont.png"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear));
text = new Text("text", "");
text.setLocalTranslation(650, 100, 0);
text.setRenderState(tsFont);
text.setLocalScale(3f);
text.setTextColor(ColorRGBA.black);
return text;
}
public void update(float tpf){
super.update(tpf);
//Show "Presenta:"
float time = Timer.getTimer().getTimeInSeconds();
if(time > 0.5f*(indice+3.5) && indice<10){
txtObj.print(presenta[indice]);
indice++;
}
//Change Alpha logoQuad
opacityAmount += step * tpf;
// check for limits
if (opacityAmount < 0.0) {
opacityAmount = 0.0f;
step = -step;
}
if (opacityAmount > 1.0f) {
opacityAmount = 1.0f;
step = -step;
}
// change the opacity of the sphere material
materialState.getDiffuse().a = opacityAmount;
getRootNode().updateRenderState();
//fader.update(1f);
//else GameStateManager.getInstance().activateChildNamed("mainMenuState");
}
}
The important part is at logoQuad, this is the spatial on i want the effect, by this look at materialState and alphaState.