Hey,
I was wondering how to make a main menu for a game. I don’t know what tool to use, so it would be nice if someone could help me with that. Also, I was asking myself if the class with the menu is suppose to have the main method in it for a simple Application. In addition to all this, if ,example, I place a button to start the game, should it trigger the app.start() instruction.
Thanks and don’t be tough with me, I’m new with all this programming stuff:)
@author normenhansen
*/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry(“Box”, b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
public void startGame(String nextScreen) {
nifty.gotoScreen(nextScreen); // switch to another screen
// start the game and do some more stuff…
}
public void quitGame() {
app.stop();
}
public String getPlayerName(){
return System.getProperty(“user.name”);
}
}
[/java]
I did everything as the tutorial said, but it didn’t wokr at me. Actually I’m not so suprised, cuz in the tutorial I didn’t see anything about “turning on” the GUI.
PS.: I slept 5 hours in the last 3 days, so I’m pretty sure I did something wrong.
NiftyJmeDisplay display = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, viewPort); //create jme-nifty-processor
guiViewPort.addProcessor(display); //add it to your gui-viewport so that the processor will start working
Nifty nifty = display.getNifty();
nifty.gotoScreen(“yourWishedScreenId”); //load the screen of choice
show us the new code you have tried, mainly simpleInitApp (assuming you haven’t changed anything else). Also what nifty warnings/errors are you getting?
There are no errors or exceptions at all negihter at the Design view of the xml and negihter in the log when I run it. I think the problem coudl be that I didn’t “connect” the GUI to the game at some palce where I should have.
Here is the Main class after I added the code ceiphren suggested:
[java]
package mygame;
@author normenhansen
*/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
NiftyJmeDisplay display = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, viewPort); //create jme-nifty-processor
guiViewPort.addProcessor(display); //add it to your gui-viewport so that the processor will start working
Nifty nifty = display.getNifty();
nifty.gotoScreen("start"); //load the screen of choice
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
[java]MyStartScreen startScreen = new MyStartScreen ();
NiftyJmeDisplay display = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, viewPort); //create jme-nifty-processor
guiViewPort.addProcessor(display); //add it to your gui-viewport so that the processor will start working
Nifty nifty = display.getNifty();
nifty.fromXML(“Interface/xmlNameGoes.xml”, “start”, startScreen);[/java]
I think what I’m doing in this topic is pushing the limits of harresment, but I’ve got another problem:D
As the tutorial said, I can call functions from the XML file, as it was writen in the example:
[java]
<text text="${CALL.getPlayerName()}'s Cool Game" font=“Interface/Fonts/Default.fnt” width=“100%” height=“100%” />
[/java]
It’s working properly on the start screen, but only show the original “${CALL.getPlayerName()}'s Cool Game” text on the hud screen, instead of the return value.
I was checking around on the net and the forum, but couldn’t find anything about it.
Never mind, I fixed it. I forgot to add the control to the hud screen. What a noob move:D But I have antoher problem. I wrote a function, and it doesn’t seem to work, but I don’t get why.
The function is in the MyStartScreen class:
[java]
public String getPlayerLuck(){
return Integer.toString(app.player.luck);
}
[/java]
app is the Main class, player is a field in Main, Player type, and luck is a field in Player class, integer type.