hello guys… for (at least) 2 days, i m trying to get a simple example of niftyGUI to work …
i m now seeing what my problem is … my bind method wont be called
furthermore my xml file just cant find my ControllerClass … so i think these problems are linked together…
btw … yeah i searched at this forum and other sources (which took most of the time of these 2 days)
all files are in NiftyGui/src/mygame/
newNiftyGui.xml :
[xml]<screen id=“start” controller=“ControllerTest”>
<layer id=“layer” backgroundColor="#003f" childLayout=“center”>
<panel id=“panel” height=“25%” width=“35%” align=“center” valign=“center” backgroundColor="#f60f" childLayout=“center” visibleToMouse=“true”>
<interact onClick=“quit()”/>
<effect>
<onStartScreen name=“move” mode=“in” direction=“top” length=“300” startDelay=“0” inherit=“true”/>
<onEndScreen name=“move” mode=“out” direction=“bottom” length=“300” startDelay=“0” inherit=“true”/>
<onHover name=“pulsate” scaleFactor=“0.008” startColor="#f600" endColor="#ffff" post=“true”/>
</effect>
<text id=“text” font=“aurulent-sans-17.fnt” color="#000f" text=“Quit” align=“center” valign=“center” />
</panel>
</layer>
</screen>
[/xml]
[java]
public class ControllerTest implements ScreenController {
NiftyJmeDisplay niftydisplay= null;
Nifty nifty = null;
Screen screen = null;
public ControllerTest(Main game) {
niftydisplay = new NiftyJmeDisplay(
game.getAssetManager(),
game.getInputManager(),
game.getAudioRenderer(),
game.getGUIViewPort());
nifty = niftydisplay.getNifty();
nifty.fromXml(“src/mygame/newNiftyGui.xml”,“start”);
game.getGUIViewPort().addProcessor(niftydisplay);
}
public void bind(Nifty nifty, Screen screen) {
System.out.println(“hallo”);
this.nifty = nifty;
this.screen = screen;
}
public void onStartScreen() { System.out.println(“onStart”);}
public void onEndScreen() { }
public void quit() {
System.out.println(“exit”);
}
}
[/java]
and finally
Main.java
[java]
public class Main extends SimpleApplication {
public Nifty nifty;
public ControllerTest myControl;
…
@Override
public void simpleInitApp() {
myControl = new ControllerTest(this);
flyCam.setEnabled(false);
}
…
}
[/java]
i tried nearly everthing (the right one wasnt there though)
last thing to say is :
i tried in the xml file several things too like:
controller=“src.mygame.ControllerTest”
or
controller=“mygame.ControllerTest”
or “/” instead of “.”
nothing changed …
the error occure is a classnotfoundexception of ControllerTest
would be REALLY great if someone knock off my stupid lines ^^
thanks in advance!
edit:
if i use controller=“mygame/ControllerTest” there is a new error message : NoClassDefFoundException “illegal name”
so there is a problem with my librarys or what else?!
Hello,
Nifty use the assetmanager from your main class.
The assetmanager store the possible locations of your files. By default, it looks inside the directory “assets” ( if my memory is good )
It’s best to disjoin Java sources from XML data.
I suggest you store your xml files inside a directory below assets.
Project
– src
– assets
– -- xml
Then register the XML path inside your main class
[java]
public class Main extends SimpleApplication {
public Nifty nifty;
public ControllerTest myControl;
…
@Override
public void simpleInitApp()
{
assetManager.registerLocator( “assets/xml/”, FileLocator.class );
myControl = new ControllerTest(this);
flyCam.setEnabled(false);
}
…
}
[/java]
For your controller. it’s the name of the whole class name you have to use.
In your file ControllerTest.java, the firsts line should be something like :
[java]
package mygame;
[…]
public class ControllerTest implements ScreenController {
[/java]
Then in your xml file, you have to write :
[java]
|screen id=“start” controller=“mygame.ControllerTest”|
[/java]
Warning : it’s case sensitive
in fact i had the package line in my file, but didnt copied it all ^^
i tried ur advices but the problem is still there … seems the xml file doesnt find the controller class
controller= “mygame/ControllerTest” seems to be an illegal name …
so i still dont know what the problem is …
but thx anyway for a try i m glad there was some1 who actually tried, cuz i dont know anything at all now
in my opinion i tried everything…except the right one ^^
Sorry, I didn’t see my xml part wasn’t visible.
Did you try “mygame.ControllerTest” ?
i did it, but tried now again :
“12.12.2010 12:19:27 de.lessvoid.xml.tools.ClassHelper getInstance
WARNING: class [mygame.ControllerTest] could not be instanziated (java.lang.InstantiationException: mygame.ControllerTest)”
terry said:
i did it, but tried now again :
"12.12.2010 12:19:27 de.lessvoid.xml.tools.ClassHelper getInstance
WARNING: class [mygame.ControllerTest] could not be instanziated (java.lang.InstantiationException: mygame.ControllerTest)"
The ControllerTest class needs to have an empty constructor.
it worked! thx!
i would have another question if u dont mind:
i m looking for a way to let the main class and the controller classe interact
[java]
public Main() {
controller = new ControllerTest();
}
[/java]
in simple update()
[java]
niftydisplay = new NiftyJmeDisplay(
assetManager,
inputManager,
audioRenderer,
guiViewPort);
nifty = niftydisplay.getNifty();
nifty.fromXml(“src/mygame/assets/xml/newNiftyGui.xml”,“start”);
nifty.getScreen(“start”).setScreenController(controller);
guiViewPort.addProcessor(niftydisplay);
[/java]
i made something like this and called in the simpleupdate() a method in the controller class like getXYZ()
but it seems this controller i declared and the controller which is actually used are differenet instances, or?
i tried a simple String-changing in the controller and then it should have compared with a string declared in the main class.
it didnt work … so i have to know how it should work … in the other topic there was an example but in fact the setScreenController(controller) didnt worked for me…
anyway, great thx to both of u who helped me out until now!
When you intances a new Nifty it will creator it’s own ScreenController by default.
If you want to use one yuourpreviously created, use this :
[java]
nifty.fromXml(“src/mygame/assets/xml/newNiftyGui.xml”,“start”, controller);
[/java]
the forum was down and i had to look at some other code instead first… and i found just that line u wrote 2hours ago!
but thank u very much! to bad the site was down… it would have spared me quite some time.
but dont really understand why the other line didnt work as well… anyway thank u! now i can finally proceed
greetings
Terry