Deliverd as promised:
Now we just need a short small chime like sound for it?
package jme3.intro;
import jme3test.app.state.RootNodeState;
import com.jme3.app.Application;
import com.jme3.app.state.AppStateManager;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
public class IntoAppState extends RootNodeState {
public final static float bgEnd = 1f;
public final static float logoEnd = 0.5f;
public final static float glow1 = 0.15f;
public final static float glow2 = 0.25f;
public final static float blendOut = 1f;
EIntroState state = EIntroState.Background;
float current = 0;
private Material bgMat;
private Material logoMat;
private Material glowMat;
private Material glow2Mat;
private AppStateManager stateManager;
private Application app;
private Material blackBG;
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.app = app;
this.stateManager = stateManager;
this.getRootNode().setQueueBucket(Bucket.Gui);
this.blackBG = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
this.blackBG.setColor("Color", ColorRGBA.Black);
this.bgMat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
Texture backgroundTex = app.getAssetManager().loadTexture("Intro/back.png");
this.bgMat.setTexture("ColorMap", backgroundTex);
this.bgMat.setFloat("AlphaDiscardThreshold", 0.01f);
this.bgMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
this.logoMat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
Texture logoTex = app.getAssetManager().loadTexture("Intro/logo.png");
this.logoMat.setTexture("ColorMap", logoTex);
this.logoMat.setFloat("AlphaDiscardThreshold", 0.01f);
this.logoMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
this.glowMat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
Texture glowTex = app.getAssetManager().loadTexture("Intro/glow.png");
this.glowMat.setTexture("ColorMap", glowTex);
this.glowMat.setFloat("AlphaDiscardThreshold", 0.01f);
this.glowMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
this.glow2Mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
Texture glow2Tex = app.getAssetManager().loadTexture("Intro/glow2.png");
this.glow2Mat.setTexture("ColorMap", glow2Tex);
this.glow2Mat.setFloat("AlphaDiscardThreshold", 0.01f);
this.glow2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
int width = app.getCamera().getWidth();
int height = app.getCamera().getHeight();
Quad geometry = new Quad(width, height);
Geometry bgQuad = new Geometry("Background", geometry);
bgQuad.setMaterial(this.bgMat);
bgQuad.setLocalTranslation(0, 0, 4);
Geometry logoQuad = new Geometry("Logo", geometry);
logoQuad.setMaterial(this.logoMat);
logoQuad.setLocalTranslation(0, 0, 5);
Geometry glowQuad = new Geometry("Glow", geometry);
glowQuad.setMaterial(this.glowMat);
glowQuad.setLocalTranslation(0, 0, 1);
Geometry bg = new Geometry("Glow", geometry);
bg.setMaterial(this.blackBG);
bg.setLocalTranslation(0, 0, 0);
Geometry glow2Quad = new Geometry("Glow2", geometry);
glow2Quad.setMaterial(this.glow2Mat);
glow2Quad.setLocalTranslation(0, 0, 2);
this.bgMat.setColor("Color", new ColorRGBA(0, 0, 0, 0));
this.logoMat.setColor("Color", new ColorRGBA(0, 0, 0, 0));
this.glowMat.setColor("Color", new ColorRGBA(0, 0, 0, 0));
this.glow2Mat.setColor("Color", new ColorRGBA(0, 0, 0, 0));
app.getGuiViewPort().attachScene(this.getRootNode());
this.getRootNode().attachChild(bg);
this.getRootNode().attachChild(bgQuad);
this.getRootNode().attachChild(logoQuad);
this.getRootNode().attachChild(glowQuad);
this.getRootNode().attachChild(glow2Quad);
}
@Override
public void update(float tpf) {
// System.out.println(tpf);
// System.out.println(this.current);
super.update(tpf);
this.current += tpf;
switch (this.state) {
case Background:
this.blend(IntoAppState.bgEnd, EIntroState.Logo, this.bgMat);
break;
case Glow1:
this.blend(IntoAppState.glow1, EIntroState.Glow2, this.glowMat);
break;
case Glow2:
this.blend(IntoAppState.glow2, EIntroState.END, this.glow2Mat);
break;
case Logo:
this.blend(IntoAppState.logoEnd, EIntroState.Glow1, this.logoMat);
break;
case END:
this.blendOut();
break;
}
}
private void blendOut() {
float ratio = 1 - FastMath.clamp(this.current / IntoAppState.blendOut, 0, 1);
this.blackBG.setColor("Color", new ColorRGBA(ratio, ratio, ratio, ratio));
this.bgMat.setColor("Color", new ColorRGBA(ratio, ratio, ratio, ratio));
this.logoMat.setColor("Color", new ColorRGBA(ratio, ratio, ratio, ratio));
this.glowMat.setColor("Color", new ColorRGBA(ratio, ratio, ratio, ratio));
this.glow2Mat.setColor("Color", new ColorRGBA(ratio, ratio, ratio, ratio));
if (this.current > IntoAppState.blendOut) {
this.app.getGuiViewPort().detachScene(this.getRootNode());
this.stateManager.detach(this);
}
}
private void blend(float endOfPart, EIntroState nextState, Material stateMat) {
float ratio = FastMath.clamp(this.current / endOfPart, 0, 1);
stateMat.setColor("Color", new ColorRGBA(ratio, ratio, ratio, ratio));
if (this.current > endOfPart) {
this.state = nextState;
this.current = 0;
}
}
private enum EIntroState {
Background, Logo, Glow1, Glow2, END
}
}