Hello everyone,
I'm having some trouble implementing GameStates into my game so I was hoping to get some advice on what might be wrong.
I have implemented things based around the TestGameStateSystem, with my main game in a BasicGameState. Everything works fine in the beginning, the "menu" state loads correctly and when I enter my game it runs everything it should, attaching children to their nodes etc. But, when everything is done loading, im faced with a black screen. I can see from my logging that I get response from the game and the input, and the strangest thing is that if I flick around the camera in frustration (as in really fast in all directions) I can sometimes see graphical elements, or part of them, pop into view for a split-second. I'll paste some code if you want but since I'm not really sure where the problem originates from I'll wait for some response before I do that.
Update:
So I've been working some more and now the scene renders for a very short time (1 frame?) when I go into the BasicGameState before everything goes black as before.
Here is the render and update in my GameStateManager:
protected final void update(float interpolation) {
// Recalculate the framerate.
timer.update();
tpf = timer.getTimePerFrame();
// Update the current game state.
GameStateManager.getInstance().update(interpolation);
}
protected final void render(float interpolation) {
// Clears the previously rendered information.
display.getRenderer().clearBuffers();
// Render the current game state.
GameStateManager.getInstance().render(tpf);
}
And this is how it looks in my BasicGameState:
public GameplayState(String name) {
super(name);
width = DisplaySystem.getDisplaySystem().getWidth();
height = DisplaySystem.getDisplaySystem().getHeight();
cam = DisplaySystem.getDisplaySystem().getRenderer().createCamera(width, height);
fpscam =
DisplaySystem.getDisplaySystem().getRenderer().createCamera(
width,
height);
cam.setFrustumPerspective(45.0f, (float) width / (float) height, 1,
5000);
/** Signal that we've changed our camera's location/frustum. */
cam.update();
fpscam.setFrustumPerspective(45.0f,
(float) width /
(float) height, 1, 5000);
Vector3f loc = new Vector3f(30.0f, 30.0f, 30.0f);
Vector3f left = new Vector3f( -1.0f, 0.0f, 0.0f);
Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
/** Move our camera to a correct place and orientation. */
fpscam.setFrame(loc, left, up, dir);
/** Signal that we've changed our camera's location/frustum. */
fpscam.update();
InitGame();
KeyBindingManager.getKeyBindingManager().set(
"exit",
KeyInput.KEY_ESCAPE);
}
/**
* During an update we only look for the escape button and update the timer
* to get the framerate.
*
* @see com.jme.app.BaseGame#update(float)
*/
public void update(float tpf) {
if (KeyBindingManager.getKeyBindingManager().
isValidCommand("exit", false)) {
// Here we switch to the menu state which is already loaded
GameStateManager.getInstance().activateChildNamed("menu");
// And remove this state, because we don't want to keep it in memory.
GameStateManager.getInstance().detachChild("ingame");
}
// third-person stuff
tpinput.update(tpf);
grass.update(tpf);
float time = Timer.getTimer().getTimeInSeconds();
//Om tryck, aktivera beam
if(player.isBeaming()) {
player.attachChild(beam);
//Minska energi
if(charge + lastUpdate <= time)
{
player.attachChild(beam);
lastUpdate = time;
}
//Om slut p
Hi!
Could you please check for
if (Float.isNaN(cam.getLocation().y )
{
System.out.println("NAN detected");
}
I have a similar problem my Camera gets changed during the update most of the time successfully but under rare circumstances it get out of the sudden a NaN value in its coords. Screen is black than obviously.