l_l
January 24, 2008, 7:23pm
1
i'm wondering if anyone has implemented a spinning "barber's pole" progress bar for the LoadingGameState? some of my users think my game is stalled when the progress bar doesn't move for a few seconds. i tried using a textured cylinder rotating like a barrel but couldn't get it to appear correctly. (see below)
i guess i could use a quad and move a texture across it, thereby simulating the barber's pole. but if someone else has already built it, i'd be happy
protected void init() {
[...]
progressCylinder = new Cylinder("Cylinder", 20, 20, 20, 120);
progressCylinder.setRenderQueueMode(Renderer.QUEUE_ORTHO);
progressCylinder.setRenderState(mytexturestate);
progressCylinder.updateRenderState();
rootNode.attachChild(progressCylinder);
[...]
}
public void update(float tpf) {
cylinderRotation += tpf;
progressCylinder.setLocalRotation(quat(cylinderRotation));
rootNode.updateGeometricState(tpf, true);
}
private Quaternion quat(float r) {
Quaternion rotation = new Quaternion();
rotation.fromAngles(r, 0, 0);
return rotation;
}
animating the texture's translation vector would be a lot easier and cheaper.
I think you don't want to render the cylinder in ortho queue.
Then you need a bit Light to get the Texture to show (the light is disabled by default in the LoadingGamestate.
And then you need to rotate the cylinder properly.
I fixed your example :) maybe thats more what you want:
package loadinganim;
import jmetest.curve.TestBezierCurve;
import com.jme.image.Texture;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Cylinder;
import com.jme.scene.state.CullState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jmex.game.state.load.LoadingGameState;
public class AnimationGamestate extends LoadingGameState {
private Node cylinderNode ;
private Cylinder progressCylinder;
private TextureState mytexturestate;
private float cylinderRotation = 0.3f;
public AnimationGamestate() {
cylinderNode = new Node("cylNode");
progressCylinder = new Cylinder("Cylinder", 20, 20, 2, 20);
progressCylinder.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y));
cylinderNode.attachChild(progressCylinder);
cylinderNode.setLocalTranslation(0, 5, 0);
rootNode.attachChild(cylinderNode);
mytexturestate = DisplaySystem.getDisplaySystem().getRenderer()
.createTextureState();
mytexturestate.setTexture(
TextureManager.loadTexture(
TestBezierCurve.class.getClassLoader().getResource(
"jmetest/data/images/Monkey.jpg"),
Texture.MM_LINEAR,
Texture.FM_LINEAR));
progressCylinder.setRenderState(mytexturestate);
CullState cs = DisplaySystem.getDisplaySystem().getRenderer().createCullState();
cs.setCullMode(CullState.CS_BACK);
progressCylinder.setRenderState(cs);
rootNode.setLightCombineMode(LightState.INHERIT);
rootNode.updateRenderState();
}
public AnimationGamestate(int steps) {
super(steps);
}
@Override
public void update(float tpf) {
super.update(tpf);
cylinderRotation += tpf;
cylinderNode.setLocalRotation(quat(cylinderRotation));
rootNode.updateGeometricState(tpf, true);
}
private Quaternion quat(float r) {
Quaternion rotation = new Quaternion();
rotation.fromAngles(r, 0, 0);
return rotation;
}
}
edit:
to use it you can alter the TestLoadingGamestate:
// Create LoadingGameState and enable
// LoadingGameState loading = new LoadingGameState();
GameTaskQueueManager.getManager().update(new Callable<Object>() {
public Object call() throws Exception {
loading = new AnimationGamestate();
return null;
}
}).get();