I have been following the NIFTY GUI tuts and I would like to make it so when the player clicks the start button. It goes to the main level. The level is the Test1.java class
This is my StartScreen.Java which i followed in the tut and is an app state. The test1.java is not an app state so may that affect it?(but is .java)
package mygame;
public class StartScreen extends AbstractAppState implements ScreenController {
public ViewPort viewport;
public Node rootNode;
public Node guiNode;
public AssetManager assetManager;
public static void main(String[] args) {
StartScreen app = new StartScreen();
app.start();
}
public StartScreen(SimpleApplication app){
this.rootNode = app.getRootNode();
this.viewport = app.getViewPort();
this.guiNode = app.getGuiNode();
this.assetManager = app.getAssetManager();
}
private StartScreen() {
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
//TODO: initialize your AppState, e.g. attach spatials to rootNode
//this is called on the OpenGL thread after the AppState has been attached
}
@Override
public void update(float tpf) {
//TODO: implement behavior during runtime
}
@Override
public void cleanup() {
super.cleanup();
//TODO: clean up what you initialized in the initialize method,
//e.g. remove all spatials from rootNode
//this is called on the OpenGL thread after the AppState has been detached
}
public void bind(Nifty nifty, Screen screen) {
}
public void onStartScreen() {
}
public void onEndScreen() {
}
/** custom methods*/
public void startGame(String Test1) {
app.start(Test1);
}
public void quitGame() {
app.stop();
}
public void start() {
}
indent preformatted text by 4 spaces
I have changed from Main to StartScreen if that helps ( I have changed it back)
public static void StartScreen(String[] args) {
StartScreen app = new StartScreen();
app.start();
}
It is now saying it does not have a main method.
I am confused can I have two main classes or will they conflict with each other and/or cause problems?
As the Test1 is the main class and contains the main game code.
It seems like you are fairly new to Java. That will be a great hinderance as you continue.
AppStates are for adding things to the Application⌠but you still need a SimpleApplication subclass with a static main() method. This is how your Java application will start.
Applications HAVE app states. They are NOT app states.
This is a fundamental disconnect and so we canât even begin to know how to answer you properly. If youâd done the tutorials then youâd already know this, I guess. AppState != Application. You have ONE Application that has SOME appstates inside of it.
I mean, so far what you are saying is like âI really want to go to the store, can someone help me flip my car upside down?â It makes no sense and has nothing to do with your end goal⌠but we donât even know enough to tell you how to correct your thinking.
I just want help to solve this Issue and be done with it.
It is extremely frustating that a (seems) simple menu screen to game does not work . I want you to help me solve this issue not lecture me. Now please help me. And I apologise if I am somehow coming across as aggresive but all I want here is help. As I am sure you were in my shoes asking for help in forms when you were a newbie and the person before you . So please help. Thank you
We donât have enough information to help you. Iâm sorry. Youâve shown us only a tiny part of the problem⌠we donât see your main application. We only see that you are somehow trying to start an app state from the command line⌠which is completely wrong.
Can you explain how we are supposed to help when you seem not to even know how to create a game application in JME? I mean, show us that we are wrong because thatâs what it looks like. We are not insulting you or giving you lectures⌠but really, how can we help?
What I am trying to do is from following the Nifty Gui tuts is make a main menu screen where there is two buttons a start and quit button. The start button will launch the test1.java file (game code) and the quit button will quit to desktop (but for now quits the application)
I heard you can accomplish this with Appstates I may have confused this as your said with being separate things. But as come to may understanding the whole project is an application for which has Appstates already built/coded in.?
I was following the nifty tut and made an Appstate and named it StartScreen and followed the tut until it said
âŚ
/** custom methods */
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();
}
âŚ
}
I would like to make it so when you press the start button it would go to the game and run the test1.java which contains the game such as the models/physics etc.
Weâre not trying to be rude to you or anything, with your knowledge the fastest and easiest way for you to solve this problem would really be to go through the tutorials on the wiki and learn how the Application hangs together with AppStateâs and I canât stress this enough, please learn this before even getting into physics and collision and other more advanced topics.
The first two lines of code I gave you pretty much sums up the solution just as @pspeed explained it to you.
Create a class MyGame extends SimpleApplication, see the tutorial on how to do this.
Create two more classes, MainMenuAppState and GameAppState, both extending AbstractAppState.
Use the code I posted at the top of this topic for switching from MainMenuAppState to GameAppState.