For an exercise, I made 2 game states. SkyboxState that attach a skybox into its root node and TerrainState that attach a terrain into its root node.
then in my Standard game declare the two game states and set it both to active. Heres what happen, the skybox appears (for a second) then disappear and shows only the terrain.
here my little code:
public class PhinTourStandardGame {
public static void main(String[] args){
StandardGame game = new StandardGame("THE STANDARD GAME");
game.start();
SkyboxState sbState = new SkyboxState();
GameStateManager.getInstance().attachChild(sbState);
sbState.setActive(true);
TerrainState terrainState = new TerrainState();
GameStateManager.getInstance().attachChild(terrainState);
terrainState.setActive(true);
}
}
*I tried adding a DebugGameState, it work fine with my terrainState but again my skyboxState disappears
So guys, how do you set up multiple game states in your standard game. Im sorry im so noob :D by the way im still using jme2
jme2 StandardGame…Are you using jME2's skyBox if so do you have the skyBox in a GametaskQueue as displayed below, if you are then can you post your code of both terrainState and skyboxState
example from very old code
GameTaskQueueManager.getManager().update
(new Callable<Object>() {
public Object call() throws Exception {
state1= new SkyBoxManager.SkyBoxGameState(); // Create our game state
//Initiate Skybox
GameStateManager.getInstance().attachChild(state1); // Attach it to the GameStateManager
state1.setActive(true); // Activate it
return state1;
}
}
).get();
@sbook and Bonechilla, here the code for the game states :D
@ Bonechilla, yeah i have my skybox inside the GameTaskQueueManager. My skyboxState works fine with DebugGameState only if the terrainState is not active.
heres my code… i have separate classes that generate the skybox for me, same also for the terrain.
SkyBoxState class
public class SkyboxState extends GameState{
Node rootNode;
public SkyboxState(){
rootNode = new Node("THE ROOT NODE");
@Override
public void update(float tpf) {
rootNode.updateGeometricState(tpf, true);
rootNode.updateRenderState();
}
@Override
public void render(float tpf) {
DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
rootNode.draw(DisplaySystem.getDisplaySystem().getRenderer());
}
@Override
public void cleanup() {
}
}
and heres the class that generates my skybox for me.
public class PhinTourSkyBox extends Skybox{
//dir, will hold the directory name
private String dir;
//ext, will hold the file extension of the images
//that will be use for textures
private String ext;
private void setSkyBoxTexture(){
//generate a URL base on the given dir
URL baseDir = PhinTourSkyBox.class.getClassLoader().getResource("data/skybox/" + dir + "/");
//resource locator uses the base directory
try {
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(baseDir));
public TerrainState(){
rootNode = new Node("THE NODE");
SpaceTerrain0 sp = new SpaceTerrain0("THE TERRAIN");
tb = sp.getTerrain();
rootNode.attachChild(tb);
}
@Override
public void update(float tpf) {
rootNode.updateRenderState();
rootNode.updateGeometricState(tpf, true);
}
@Override
public void render(float tpf) {
DisplaySystem.getDisplaySystem().getRenderer().clearBuffers();
rootNode.draw(DisplaySystem.getDisplaySystem().getRenderer());
}
@Override
public void cleanup() {
}
}
and the class that generate my terrain
public class SpaceTerrain0{
private TerrainBlock tb;
private String id;
public SpaceTerrain0(String id){
this.id = id;
setTerrain();
}
public TerrainBlock getTerrain(){
return tb;
}
private void setTerrain(){
//set the height map
MidPointHeightMap heightMap = new MidPointHeightMap(64, 1.0f);
//create a vector3f for the scale value
Vector3f terrainScale = new Vector3f(4, 0.1f, 4);
//create the terrain block
tb = new TerrainBlock(id, heightMap.getSize(), terrainScale,
heightMap.getHeightMap(), new Vector3f(0,0,0));
//set the nounding volume for the terrain block
tb.setModelBound(new BoundingBox());
tb.updateModelBound();
//create the base texture based on pt
Texture baseTex = TextureManager.loadTexture(
pt.getImageIcon().getImage(),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear,
true);
//combine the two textures
//set the combination settings
baseTex.setApply(Texture.ApplyMode.Combine);
baseTex.setCombineFuncRGB(Texture.CombinerFunctionRGB.Modulate);
baseTex.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
baseTex.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
baseTex.setCombineSrc1RGB(Texture.CombinerSource.PrimaryColor);
baseTex.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);
baseTex.setCombineScaleRGB(Texture.CombinerScale.One);
I thought, that this method would clear the whole screen? I suppose that GameStateManager should take care of this, your GameStates should only draw there part of things..
At least that explains me, why your Skybox disappears, because the TerrainGameState would clear the buffers AFTER your SkyBoxState rendered.
And is it intended to create a BlendState without assigning it to any spatial? (you do it each render cycle of your SkyBoxGameState:)
I thought, that this method would clear the whole screen? I suppose that GameStateManager should take care of this, your GameStates should only draw there part of things..
At least that explains me, why your Skybox disappears, because the TerrainGameState would clear the buffers AFTER your SkyBoxState rendered.
And is it intended to create a BlendState without assigning it to any spatial? (you do it each render cycle of your SkyBoxGameState:)
haha! silly me, for always putting what's in the tutorial. yes the terrain do clear the whole screen thats why the skybox disappears. the createBlendState is supposed to be clearBuffers(), anyway i just deleted them. thanks.. im sorry i didnt notice im clearing the screens.. well this case is solved. :D
I thought, that this method would clear the whole screen? I suppose that GameStateManager should take care of this, your GameStates should only draw there part of things..
At least that explains me, why your Skybox disappears, because the TerrainGameState would clear the buffers AFTER your SkyBoxState rendered.
And is it intended to create a BlendState without assigning it to any spatial? (you do it each render cycle of your SkyBoxGameState:)
haha! silly me, for always putting what's in the tutorial. yes the terrain do clear the whole screen thats why the skybox disappears. the createBlendState is supposed to be clearBuffers(), anyway i just deleted them. thanks.. im sorry i didnt notice im clearing the screens.. well this case is solved. :D
Haha :)
I was already wondering if createBlenderState was a too fast use of Code Autocompletion :D
Happy to hear, it helped you :D