Start Game

hi guys
i make screens and i want startGame when the user click on the Button
,i do it but the game begain befor is click on the button the game run when i run the project :smiley:
How can make the game run after the user click on the button :slight_smile:

hi guys
i have a little problem i have screens and class to control screens and i have anther main class that run the game i want when i click the button of start game he build this main class
how can do this please i need help :frowning:

<?xml version="1.0" encoding="UTF-8"?> <nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd"> <useStyles filename="nifty-default-styles.xml" /> <useControls filename="nifty-default-controls.xml" /> <!-- +++++++++++++++++++++++++++++++++++++++ --> <!-- start screen --> <!-- +++++++++++++++++++++++++++++++++++++++ --> <screen id="start" controller="jme3test.helloworld.MyScreenController"> <layer id="background" childLayout="center" > <image filename="Interface/backGround.jpg" height="100%" width="100%"></image> </layer> <layer id="foreground" align="center" childLayout="vertical"> <panel id="panel_top" height="30%" width="100%" align="center" childLayout="center"/> <panel id="start_button" height="15%" width="40%" align="center" childLayout="center"> <control name="button" label="Start Game" id="StartButton" height="50%" width="50%" align="center" visibleToMouse="true"> <interact onClick="Next(Game)" /> </control> </panel> <panel id="how_button" height="15%" width="40%" align="center" childLayout="center"> <control name="button" label="How To Play" id="HowButton" height="50%" width="50%" align="center" visibleToMouse="true"> <interact onClick="Next(How_to_play)" /> </control> </panel> <panel id="about_button" height="15%" width="40%" align="center" childLayout="center"> <control name="button" label="About" id="AboutButton" height="50%" width="50%" align="center" visibleToMouse="true"> <interact onClick="Next(about)"/> </control> </panel> <panel id="quit_button" height="15%" width="40%" align="center" childLayout="center"> <control name="button" label="Quit" id="QuitButton" height="50%" width="50%" align="center" visibleToMouse="true"> <interact onClick="quitGame()"/> </control> </panel> </layer> </screen> <screen id="control" controller="jme3test.helloworld.MyScreenController"> <layer id="background" childLayout="center" > <image filename="Interface/control.jpg" height="100%" width="100%"></image> </layer> <layer id="foreground" align="center" childLayout="vertical"> <panel id="panel_top" height="85%" width="100%" align="center" childLayout="center"/> <panel id="start_control" height="15%" width="40%" align="center" childLayout="center"> <control name="button" label="Back" id="BackButton" height="50%" width="50%" align="center" visibleToMouse="true"> <interact onClick="Next(How_to_play)"/> </control> </panel> </layer> </screen> <screen id="about" controller="jme3test.helloworld.MyScreenController"> <layer id="background" childLayout="center" > <image filename="Interface/About.jpg" height="100%" width="100%"></image> </layer> <layer id="foreground" align="center" childLayout="vertical"> <panel id="panel_top" height="85%" width="100%" align="center" childLayout="center"/> <panel id="panel_bottom" height="15%" width="75%" align="center" childLayout="horizontal"> <panel id="Back_control" height="100%" width="20%" align="center" childLayout="center"> <control name="button" label="Back" id="BackButton" height="50%" width="50%" align="center" visibleToMouse="true"> <interact onClick="Next(start)"/> </control> </panel> </panel> </layer> </screen> <screen id="description" controller="jme3test.helloworld.MyScreenController"> <layer id="background" childLayout="center" > <image filename="Interface/About.jpg" height="100%" width="100%"></image> </layer> <layer id="foreground" align="center" childLayout="vertical"> <panel id="panel_top" height="85%" width="100%" align="center" childLayout="center"/> <panel id="panel_bottom" height="15%" width="75%" align="center" childLayout="horizontal"> <panel id="Back_control" height="100%" width="20%" align="center" childLayout="center"> <control name="button" label="Back" id="BackButton" height="50%" width="50%" align="center" visibleToMouse="true"> <interact onClick="Next(start)"/> </control> </panel> </panel> </layer> </screen> <screen id="How_to_play" controller="jme3test.helloworld.MyScreenController"> <layer id="background" childLayout="center" > <image filename="Interface/backGround.jpg" height="100%" width="100%"></image> </layer> <layer id="foreground" align="center" childLayout="vertical"> <panel id="panel_top" height="40%" width="100%" align="center" childLayout="center"/> <panel id="start_control" height="15%" width="40%" align="center" childLayout="center"> <control name="button" label="Control" id="ControlButton" height="50%" width="50%" align="center" visibleToMouse="true"> <interact onClick="Next(control)"/> </control> </panel> <panel id="panel_description" height="15%" width="40%" align="center" childLayout="center"> <control name="button" label="Description" id="DescriptionButton" height="50%" width="50%" align="center" visibleToMouse="true"> </control> </panel> <panel id="panel_Back" height="15%" width="40%" align="center" childLayout="center"> <control name="button" label="Back" id="BackButton" height="50%" width="50%" align="center" visibleToMouse="true"> <interact onClick="Next(start)"/> </control> </panel> </layer> </screen> <screen id="Game" controller="jme3test.helloworld.MyScreenController"> <layer id="background" childLayout="center" >
    &lt;/layer&gt;
&lt;/screen&gt;

</nifty>

[java] package jme3test.helloworld;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import de.lessvoid.nifty.Nifty;

/**

  • Nifty GUI 1.3 demo using XML for static content and Java for dynamic content.

  • @author zathras
    */
    public class MyMain extends SimpleApplication {

    private MyScreenController startScreen;

    public static void main(String args) {
    MyMain app = new MyMain();
    AppSettings settings = new AppSettings(true);
    settings.setFullscreen(true);
    app.setShowSettings(true); // splashscreen
    app.setSettings(settings);
    app.start();
    }

    @Override
    public void simpleInitApp() {
    setDisplayFps(false);
    setDisplayStatView(false);

     startScreen = new MyScreenController();
     stateManager.attach(startScreen);
    
     NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
             assetManager, inputManager, audioRenderer, guiViewPort);
     Nifty nifty = niftyDisplay.getNifty();
     guiViewPort.addProcessor(niftyDisplay);
     nifty.fromXml("Interface/startScreen.xml", "start", startScreen);
    
     flyCam.setDragToRotate(true);
    

    }
    }
    [/java]
    [java]
    package jme3test.helloworld;

import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

/**
*
*/
public class MyScreenController extends AbstractAppState implements ScreenController {

private Nifty nifty;
private Application app;
private Screen screen;
private boolean go=true;
public static MainClass App = new MainClass();

/**
 * custom methods
 */
public MyScreenController() {
}

public void Next(String nextScreen) {
    nifty.gotoScreen(nextScreen);  // switch to another screen
    if (screen.getScreenId().equals("Game")){
        
        App.start();
    }
}

public void quitGame() {
    app.stop();
}

/**
 * Nifty GUI ScreenControl methods
 */
public void bind(Nifty nifty, Screen screen) {
    this.nifty = nifty;
    this.screen = screen;
}

public void onStartScreen() {
}

public void onEndScreen() {
}

/**
 * jME3 AppState methods
 */
@Override
public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    this.app = (SimpleApplication) app;
}

@Override
public void update(float tpf) {
    
}

}
[/java]

Your Next() function shouldnโ€™t start the application (itโ€™s running already).
You probably want to attach or enable an AppState.

Have you done the beginner tutorials? They explain that kind of thing.