Hi, when switching screens the textfield doesnt work anymore.
This is my code:
pre type="java"
public class TestNiftyGui extends SimpleApplication implements ScreenController{
private Nifty nifty;
Node shootables;
public static void main(String[] args){
TestNiftyGui app = new TestNiftyGui();
app.setPauseOnLostFocus(false);
app.start();
}
public void simpleInitApp() {
initCrossHairs();
initKeys();
shootables = new Node(“Shootables”);
rootNode.attachChild(shootables);
shootables.attachChild(makeCube(“60”, 3f, 3f, 0f));
NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
inputManager,
audioRenderer,
guiViewPort);
nifty = niftyDisplay.getNifty();
nifty.fromXml(“Interface/hellojme3.xml”, “start”,this);
// attach the nifty display to the gui view port as a processor
guiViewPort.addProcessor(niftyDisplay);
flyCam.setEnabled(false);
mouseInput.setCursorVisible(true);
nifty.getCurrentScreen().findNiftyControl(“time1”, TextField.class).setText(“hello1”);
}
public void sayHello(){
System.out.println(“hello”);
initScreen2();
}
public void sayHello2(){
System.out.println(“hello2”);
initScreen3();
}
public void bind(Nifty nifty, Screen screen){
};
public void onStartScreen(){
};
public void onEndScreen(){
};
/** A cube object for target practice */
protected Geometry makeCube(String name, float x, float y, float z) {
Box box = new Box(new Vector3f(x, y, z), 0.5f, 0.5f, 0.5f);
Geometry cube = new Geometry(name, box);
Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);
mat1.setColor(“m_Color”, ColorRGBA.randomColor());
cube.setMaterial(mat1);
return cube;
}
protected void initCrossHairs() {
guiNode.detachAllChildren();
guiFont = assetManager.loadFont(“Interface/Fonts/Default.fnt”);
BitmapText ch = new BitmapText(guiFont, false);
ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
ch.setText("+"); // crosshairs
ch.setLocalTranslation( // center
settings.getWidth() / 2 - guiFont.getCharSet().getRenderedSize() / 3 * 2,
settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
guiNode.attachChild(ch);
}
private void initKeys() {
inputManager.addMapping(“gui”,
new KeyTrigger(KeyInput.KEY_1));
inputManager.addListener(guiListener, “gui”);
}
protected void initScreen(){
nifty.fromXml(“Interface/hellojme3.xml”, “start”,this);
// disable the fly cam
flyCam.setEnabled(false);
mouseInput.setCursorVisible(true);
nifty.getCurrentScreen().findNiftyControl(“time1”, TextField.class).setText(“hello2”);
}
protected void initScreen2(){
nifty.fromXml(“Interface/hellojme4.xml”, “start”,this);
// disable the fly cam
flyCam.setEnabled(false);
mouseInput.setCursorVisible(true);
nifty.getCurrentScreen().findNiftyControl(“time2”, TextField.class).setText(“hello3”);
//16-apr-2011 15:07:42 de.lessvoid.nifty.screen.Screen findNiftyControl
//WARNING: missing element/control with id [time2] for requested control class [de.lessvoid.nifty.controls.TextField]
}
protected void initScreen3(){
nifty.exit();
flyCam.setEnabled(true);
mouseInput.setCursorVisible(false);
}
private ActionListener guiListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals(“gui”) && !keyPressed) {
initScreen();
}
}
};
}
/pre
And the xml:
pre type="xml"
<nifty xmlns=“http://nifty-gui.sourceforge.net/nifty.xsd”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty.xsd
http://nifty-gui.sourceforge.net/nifty.xsd”>
/pre
second xml:
pre type="xml"
<nifty xmlns=“http://nifty-gui.sourceforge.net/nifty.xsd”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty.xsd
http://nifty-gui.sourceforge.net/nifty.xsd”>
/pre
edit: I put my code in the onStartScreen() and now it works.