Nifty gui in a game

Well i’am making a game, I add the character and the scene and now i want to add a nifty gui, I created the basic things



Menu_Display= new NiftyJmeDisplay(

assetManager, inputManager, audioRenderer, guiViewPort);



Nifty nifty = Menu_Display.getNifty();

nifty.fromXml(“Interface/Menu_interno.xml”, “start”);

guiViewPort.addProcessor(niftyDisplay);



and the Menu_interno.xml



I want that when I press a button the game be paused, how i can do that? i added onclick() to the xml and created the screen controler, but nothings hapend, what I have to do???

I don’t really get it…

If you want to pause the game, there is a paused flag in the simpleApplication.

Set it to true to pause your game

You need to supply the actual object instance of the controller class you want to use in the constructor.

yeah I´m doing that, I create the pause flag in the simpleAplication, but I need to change his value from the nifty , I´doing something like that in the screencontroller.



public class Menu_interno_screencontroller implements ScreenController {



boolean pause_game=false;



public void bind(Nifty nifty, Screen screen) {

throw new UnsupportedOperationException(“Not supported yet.”);

}



public void onStartScreen() {

throw new UnsupportedOperationException(“Not supported yet.”);

}



public void onEndScreen() {

throw new UnsupportedOperationException(“Not supported yet.”);



}



public void set_pause_game(String pausa){

if(pausa.Equals(Pausar))

this.pause_game=true;

}



public boolean get_pause_game(){

return pause_game;

}





in the simple aplication I create



private Menu_interno_screencontroller scontroller;



public void simpleUpdate(float tpf) {



scontroller.get_pause_game();





}





But nothing hapend

What should happen? get_pause_game() returns a boolean and thats it…

I don’t know, the gui doesn´t detect the click, this is my .xml


<?xml version="1.0" encoding="UTF-8"?>






































How would you know if it did or not? You don’t do anything that would output something or have any effect at all.

normen said:
How would you know if it did or not? You don't do anything that would output something or have any effect at all.

sometimes is really funny and it feels good seeing someone dummer then you. Well works for me anyway >.>

Oh, and actually your ScreenController is definitely not called, it would throw an UnsupportedOperationException(“Not supported yet.”)

how i call it?

[java]

niftyDisplay = new NiftyJmeDisplay(assetManager,

inputManager,

audioRenderer,

guiViewPort);

nifty = niftyDisplay.getNifty();

try {

nifty.fromXml("Interface/MyNifty.xml", "start_screen", myScreenControllerInstance);

} catch (Exception ex) {

ex.printStackTrace();

}

[/java]

I dont know, I start a new project like the tutorials





public void simpleInitApp() {

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(

assetManager, inputManager, audioRenderer, guiViewPort);

Nifty nifty = niftyDisplay.getNifty();

nifty.fromXml(“Interface/HelloWorld.xml”, “start”);



// attach the nifty display to the gui view port as a processor

guiViewPort.addProcessor(niftyDisplay);



// disable the fly cam

flyCam.setDragToRotate(true);

}




<?xml version="1.0" encoding="UTF-8"?>









<panel height=“25%” width=“35%” align=“center” valign=“center” backgroundColor="#f60f"

childLayout=“center” visibleToMouse=“true”>



















public class controller implements ScreenController{



public void bind(Nifty nifty, Screen screen) {



}



public void onStartScreen() {

throw new UnsupportedOperationException(“Not supported yet.”);

}



public void onEndScreen() {

throw new UnsupportedOperationException(“Not supported yet.”);

}



public void funcion(){



System.out.println("Nifty says ");





}



}



and I clicked and nothing hapend, I have to enable something mouse event or what???

No, you forgot to supply the actual object instance of the controller class you want to use in the constructor.

If you could supply the XML you have for your screen as well, that would help. Because it IS possible to set the screen controller in the XML, but then you would have to do some other stuff to get a handle to that screen controller in your game loop.



Aside from that, you have this:

[java]

public void simpleUpdate(float tpf) {



scontroller.get_pause_game();



}

[/java]



This would get the pause variable from the screen controller, but you are not assigning it to the pause variable in simplegame. The returned boolean just dissapeares into thin air.

No, because I try printing the returned boolean into the get_pause_game function and nothing hapend, my problem is in the gui, that thing doesn´t detect my clicks

No, because I try printing the returned boolean into the get_pause_game function and nothing hapend, my problem is in the gui, that thing doesn´t detect my clicks

Ok, you already posted your controller, could you also post your screen xml code?

I was with the same problem, Santiago, take care with the line :

[java]nifty.fromXml("Interface/MyNifty.xml", "start_screen", myScreenControllerInstance);[/java]

remember to put the correct values in the method :wink: