Am making a simple game and have moved my game code to a new class, so now I have Main.java & GamePlay.java. Have nifty setup nicely in without using xml but can’t figure out how to start my GamePlay.java from nifty. Have looked though some examples and seen screencontroller but not sure how to make it work.
To clarify Nifty is in Main.java and my game logic sits in GamePlay.java, how do I start the GamePlay from my start button?
my Main.java
[java]
public class Main extends SimpleApplication {
public static void main(String[] args){
Main app = new Main();
app.setPauseOnLostFocus(false);
app.start();
}
public void simpleInitApp() {
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
assetManager, inputManager, audioRenderer, guiViewPort);
Nifty nifty = niftyDisplay.getNifty();
guiViewPort.addProcessor(niftyDisplay);
flyCam.setDragToRotate(true);
nifty.loadStyleFile(“nifty-default-styles.xml”);
nifty.loadControlFile(“nifty-default-controls.xml”);
// <screen>
nifty.addScreen(“start”, new ScreenBuilder(“start”) {{
controller(new DefaultScreenController());
layer(new LayerBuilder(“background”) {{
childLayoutCenter();
// add image
image(new ImageBuilder() {{
filename(“Interface/start_spiral.png”);
}});
}});
layer(new LayerBuilder(“foreground”) {{
childLayoutVertical();
// panel added
panel(new PanelBuilder(“panel_top”) {{
childLayoutCenter();
alignCenter();
height(“25%”);
width(“75%”);
// add text
text(new TextBuilder() {{
text(“Space Train 3d”);
font(“Interface/Fonts/Default.fnt”);
height(“100%”);
width(“100%”);
}});
}});
panel(new PanelBuilder(“panel_mid”) {{
childLayoutCenter();
valignTop();
alignCenter();
height(“15%”);
width(“75%”);
// add text
text(new TextBuilder() {{
text("Welcome to the amazing future where you are a gargbage man picking up space junk. "+
"Incidentally, space is a big place and the trash just keeps coming. "+
"As your working try not to crash into yourself or the forcefield. "+
"If you crash into yourself your dead, and we’re gonna work you till your dead!. "+
"There will be a short memorial for your death, afterwards you’ll be replaced. ");
font(“Interface/Fonts/Default.fnt”);
wrap(true);
height(“100%”);
width(“100%”);
}});
}});
panel(new PanelBuilder(“panel_bottom”) {{
childLayoutHorizontal();
alignCenter();
height(“25%”);
width(“75%”);
panel(new PanelBuilder(“panel_bottom_left”) {{
childLayoutCenter();
valignCenter();
height(“50%”);
width(“50%”);
// add button control
control(new ButtonBuilder(“StartButton”, “Start”) {{
alignCenter();
valignCenter();
height(“50%”);
width(“50%”);
visibleToMouse(true);
interactOnClick(“startGame(hud)”);
}});
}});
panel(new PanelBuilder(“panel_bottom_right”) {{
childLayoutCenter();
valignCenter();
height(“50%”);
width(“50%”);
// add button control
control(new ButtonBuilder(“QuitButton”, “Quit”) {{
alignCenter();
valignCenter();
height(“50%”);
width(“50%”);
visibleToMouse(true);
interactOnClick(“quitGame()”);
}});
}});
}}); // panel added
}});
}}.build(nifty));
nifty.gotoScreen(“start”);
}
}
[/java]
You don’t have a startGame() method in your main class. Make one so your line “interactOnClick(“startGame(hud)”);” has something to call, and then from there initialize your other class.