I’m experimenting with Nifty so I can make a weapon design program for one of my games, and I didn’t want to make a(nother) mess in my main project.
So basically I took the jme planet demo, and attempted to add 2 buttons to it.
A “create planets button” and a quit button
Here’s the XML
<!-- add your content here -->
[java]public void CreatePlanets(){
System.out.println(“The planets should be created!”);
app.initPlanets();
nifty.gotoScreen(“blank”);
}[/java]
where app is the planet application
[java]public void initPlanets(){
// Add planet app state
stateManager.detach(startState);
stateManager.attach(planetAppState);
If CreatePlanets() and Quit() are on your screen controller then how does it get its reference to app?
Have you put a println in these methods to see if it is even called?
My guess, since nifty swallows all exceptions is that you are getting a NullPointerException in these methods because your controller doesn’t have a proper reference to the application.
@pspeed said:
If CreatePlanets() and Quit() are on your screen controller then how does it get its reference to app?
Have you put a println in these methods to see if it is even called?
My guess, since nifty swallows all exceptions is that you are getting a NullPointerException in these methods because your controller doesn’t have a proper reference to the application.
I did not include this when I posted, but in theory this gets called?
I do not see any manual calling of initialize in the nifty demo but they have an app object that gets initialized in the same way. I merely added (PlanetSimpleTest) instead of (SimpleApplication) or whatever.
That only gets called if the app state is attached to the state manager. I’m assuming it’s a screen controller + app state. If you let nifty create it on its own then the initialize() will never be called because it does not get attached to the state manager. You have to create it in your code, attach it to the state manager, and give it to nifty when the XML is loaded.
@pspeed said:
That only gets called if the app state is attached to the state manager. I'm assuming it's a screen controller + app state. If you let nifty create it on its own then the initialize() will never be called because it does not get attached to the state manager. You have to create it in your code, attach it to the state manager, and give it to nifty when the XML is loaded.
I am doing that too.
[java]
startState = new StartScreen();
stateManager.attach(startState);
/**
* Åctivate the Nifty-JME integration:
*/
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(
assetManager, inputManager, audioRenderer, guiViewPort);
Nifty nifty = niftyDisplay.getNifty();
guiViewPort.addProcessor(niftyDisplay);
nifty.fromXml(“Interface/newbutton.xml”, “start”, startState);
The buttons are showing, they are highlighting on mouseover, and they are changing color when I click them, but nothing happens and my printouts don’t print out.
Bind is called by Nifty automatically when you register the screen controller. (I think it actually happens just before the first call to tell you the screen has started).
Double check your xml has the correct full name (including package) for your controller class. Your registering of the state and controller is correct so that’s the only other thing I can think of that would stop bind being called.
@zarch said:
Bind is called by Nifty automatically when you register the screen controller. (I think it actually happens just before the first call to tell you the screen has started).
Double check your xml has the correct full name (including package) for your controller class. Your registering of the state and controller is correct so that’s the only other thing I can think of that would stop bind being called.
Lol… jmeplanet.test.StartScreen
Instead of test.StartScreen