Game States

What are actually game states ? Are they supposed to be game states like ingame or menu screen ? My question is if i could

break the game itself into separate logical states and run each part separately should i do it ? Is this a good thing or just gets

things complicated ? For example making a separate game state just for controlling camera in the game .

Well, there’s a difference between JME StandardGame GameStates and game states as they’re normally used in game development, but I think JME’s GameStates are very useful to separate parts of a game, like a login screen and the in-game-state and the paused game state and so on.

I don’t really see the benefit of using a GameState to handle the camera though, but if you see it, go ahead and try it.

Here’s a good wiki entry explaining the JME(2) GameState:

http://www.jmonkeyengine.com/wiki/doku.php/standardgame_gamestates_and_multithreading_a_new_way_of_thinking

Thanks for the response

Actually i want to let the player freely move the camera around the map even if game is paused , if i have a separate thread

for camera i can just stop the game thread and let the camera thread still going . but im not experience with StandardGame

and i don't know if this is practical .

I don't mean to hijack this thread, but its similar so I thought I'd rather just ask on it :slight_smile:



I want to have the game load up, and have a login screen presented to the user. Then, once login is successful, the game must start. So, I thought that states would solve this problem.



However, I'm getting mixed understanding on some posts and tutorials. Is a GameState, just like its own BaseGame? does it have update(), render() and initSystem() methods etc?



And, do I necessarily have to use StandardGame to use states? Could I use BaseGame?

hadi:

I'm not sure how that would work.

If your main in-game state was paused and you moved the camera in another game state (if you can actually do that, I haven't tried), wouldn't your in-game state still just look the same until you started it again? So you wouldn't really notice that you were moving the camera? I'm not at all sure, so please do try, but I'm not quite sure how it would work.



Beefoid:

That's a similar setup to what we've got, so that should work.

GameStates have update(), render() and cleanup() methods so they're similar to single-threaded games on their own.

The update and render methods are called by the main game thread.

You can inherit from BaseGameState if you want a basic setup of your game state as default.



I think you can use GameStates with other game types as well but it's probably easiest to stick with StandardGame as it's all set up for you there already.

Ok thanks,



Can anyone point me in the direction of a tutorial which shows you how to integrate the Nifty Renderer with a GameState? And, I'm not using StandardGame, i'm using BaseGame.

You can use a NiftyNode in your GameState to use Nifty there.

Then in the constructor you can put:


niftyNode = new NiftyNode("GUI:NIFTYNODE", "path/to/your/layout/layout.xml", "idOfStartScreen");
rootNode.attachChild(niftyNode);


and it will be rendered when the GameState is active.

The three parameters in the NiftyNode constructor are of course dependant on your project details.

OK Cool, is that the way to use the latest version of Nifty? Version 1.2 I think it is.

I added nifty-1.2.jar and nifty-lwjgl-renderer-1.0.jar to my project, however, when I want to create a NiftyNode, the class cannot be found  :?



Have I not downloaded it or something?

If you want to use the lwjgl-renderer you don't get the NiftyNode, as that is part of the JME-renderer.

If you're using JME, why not get the JME-renderer? :slight_smile:

It seems that at the moment you can't get it from the Nifty sourceforge project page, but you can get it from the SVN repository here: https://nifty-gui.svn.sourceforge.net/svnroot/nifty-gui/nifty-jme-renderer/trunk.

So all I do is create a NiftyNode and attach it to the rootnode of the current scene?



Then I add the XML to the NiftyNode, as well as all the elements?


Yes, you give the xml of your layout to Nifty via the NiftyNode and in it you should have at least one screen which is your start screen and you give the id of the start screen to the NiftyNode and then that screen is shown when the node is rendered.

You specify your elements inside the xml-file or create them in code. If you need the Nifty instance you can get it from the NiftyNode.

Good luck!

Thanks very much!

I don't really understand the proces (LOL) but I'll read tutorials etc.