Stuck with a Nifty problem :P

Hey there fellow monkey’s!



I guess this is an intro/help request post. I’m a final year student doing my degree in computer science and for my final year project I decided to make a game for android. After a lot of scouring around and checking out a number of platforms and options I found jMonkey to be the most suitable coz I’m an open source sorta fella…



Well that apart, i went through all the tutorials, meticulously wrote each tut code down in the IDE and got em to work …great stuff !



But now that I actually started building my own game ive come to a single point and am stuck beyond all help.



My question is this:



in the Nifty GUI tutorial we created a seperate class for the gui interface and then linked it into the main game using a function like initMenu() or summat.

The gui shows just as expected with buttons et all but none of them work.I have linked the quit buttion to a function quitGame() which is as follows:



[java]public void quitGame() {

app.stop();

}[/java]



The application doesn’t quit when this is clicked.



Also, when i hit the start button which link to this function :



[java]public void startGame(String nextScreen) {

nifty.getScreen(“hud”);

}

[/java]



The next hud screen loads just fine but I can;t seem to figure out how to include a call to my loadScene() function in main.java from gui.java…



Please oh please help me because I’m at my wits end…

Um… couple questions.



Is you gui.java file a controller class for a Nifty xml file?

Is it being instantiated from main.java?

And if so… are you passing in a reference to your app class?



[java]guiClass gui = new guiClass(this);[/java]



In your gui class constructor:



[java]protected Main app;

pubic guiClass (Main app) {

this.app = app;

}



public void startGame(String nextScreen) {

nifty.getScreen(nextScreen);

app.loadScene(nextScreen);

}[/java]

Thanks a lot… :smiley:



Can’t believe I didn;t see that one… Thanks a tonne!

ummmm… doing this



[java]

public void startGame(String nextScreen) {

nifty.getScreen("hud");

System…out.println("in the startCAll");

app.loadScene();

}

[/java]



I get the output text in the console but still no scene being loaded. If i unload the GUI(ie. comment it out) it works just fine when called from within main.java

Sorry for the stupid questions, but… I’m pretty good at asking them.



Is the pointer to your main app being set properly when you instantiate the gui class?

If you move the System.out.println to your loadScene() method, do you still see it in the console?



If both of these are not issues, then the problem has to be in your loadScene() method.



Are you using callables to load geometry?



[java]public void addSceneNode(Node node, int type) {

class addNode implements Callable {

Node node;

int type;

public addNode(Node node, int type) {

this.node = node;

this.type = type;

}

public Object call() {

if (type != NODE_ROOT)

sceneGraph.get(type).attachChild(node);

else

rootNode.attachChild(node);

return null;

}

}

addNode task = new addNode(node, type);

enqueue(task);

}[/java]



The above assumes that you have defined scene nodes in your code:



[java]public static final int NODE_ROOT = 0;[/java]



I have my scene divided into collidables, liquids, etc, etc… so the application can do quick inbound checks for different physics, etc.



Your calling into the main update thread from outside of the main class at this point… which can cause problems all on its own.



There are other (I am sure more elegant) ways of doing this. Anonymous inner classes are frowned upon by some. :slight_smile:

Oh i got it to work…apparently there was a little something wrong in main.java…thanks a lot for the help tho man. :slight_smile:

had the same problem with

[java]app.stop();[/java]

use only:

[java]stop();[/java]

Kernproblem