Nifty

I just started to work with nifty and it works fine but when ever I try to give any text in .xml file the nifty stops working and the screen becomes blank. I know I am doing something wrong but what I am not sure of. This is what I have been doing.





main java class

[java]

package mainGame;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import de.lessvoid.nifty.Nifty;





public class TestNifty extends SimpleApplication{



Nifty nifty;

public static void main(String [] args)

{

TestNifty app = new TestNifty();

app.start();

}



@Override

public void simpleInitApp() {

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(

assetManager,

inputManager,

audioRenderer,

guiViewPort

);

nifty = niftyDisplay.getNifty();

nifty.fromXml("Interface/TestMyNifty.xml", "start");

guiViewPort.addProcessor(niftyDisplay);

flyCam.setDragToRotate(true);



Box b = new Box(Vector3f.ZERO,1,1,1);

Geometry geo = new Geometry("Box", b);

Material mat = new Material(assetManager,

"Common/MatDefs/Misc/Unshaded.j3md");

mat.setColor("Color", ColorRGBA.Blue);

geo.setMaterial(mat);

rootNode.attachChild(geo);

}

}

[/java]



.xml file

[xml]

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

<nifty>

<screen id="start" controller="mainGame.TestNifty">

<layer id="layer" childLayout="center">

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

childLayout="center" visibleToMouse="true" text="Hello World">

<text font="verdana-24-shadow.fnt" text="Hello World!"

align="center" valign="center" />

</panel>

</layer>

</screen>

</nifty>

[/xml]



When I introduced [xml]<text font="verdana-24-shadow.fnt" text="Hello World!"align="center" valign="center" />[/xml] nifty stops working and I dont know why.



If any one can give a good place where i can find some good nifty tutorials it will be very helpful.

Thanks

K Out!

I’m not sure what the problem is, but you can try using a label control instead of text. Something like

[xml]<control name=“label” id=“hello” text=“Hello World” width = “100” height = “20” backgroundColor="#134f" align=“center” valign=“center” />

[/xml]

Here are also tutorials http://sourceforge.net/apps/mediawiki/nifty-gui/index.php?title=Tutorials

Hey,



maybe you should first write a real ScreenController which looks like this:



[java]

public class MyController implements ScreenController {



Nifty nifty;

Screen screen;



public MyController() {

}



@Override

public void bind(Nifty nifty, Screen screen) {

this.nifty = nifty;

this.screen = screen;

}



@Override

public void onStartScreen() {



//

}



@Override

public void onEndScreen() {

}

}



[/java]



and then bind it in the xml-file :slight_smile:

thanks wezrule I tried with control but still the same problem. I will try the ScreenController that Dodikles sent. Thanks

I am still having problems. Only the first layer is being shown and the others are not plus no text is being shown. I still dont know what I am doing wrong this is what I did now.





main Java class TestNifty:

[java]

package mainGame;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;





public class TestNifty extends SimpleApplication implements ScreenController{



Nifty nifty;

Screen screen;

public static void main(String [] args)

{

TestNifty app = new TestNifty();

app.start();

}



@Override

public void simpleInitApp() {

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(

assetManager,

inputManager,

audioRenderer,

guiViewPort

);

nifty = niftyDisplay.getNifty();

nifty.fromXml("Interface/testAgain.xml", "start");

guiViewPort.addProcessor(niftyDisplay);

flyCam.setDragToRotate(true);



Box b = new Box(Vector3f.ZERO,1,1,1);

Geometry geo = new Geometry("Box", b);

Material mat = new Material(assetManager,

"Common/MatDefs/Misc/Unshaded.j3md");

mat.setColor("Color", ColorRGBA.Blue);

geo.setMaterial(mat);

rootNode.attachChild(geo);

}



public void bind(Nifty nifty, Screen screen) {

this.nifty = nifty;

this.screen = screen;

}



public void onStartScreen() {

}



public void onEndScreen() {



}



}



[/java]





testAgain.xml:

[xml]

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

<nifty>

<!-- +++++++++++++++++++++++++++++++++++++++ -->

<!-- start screen -->

<!-- +++++++++++++++++++++++++++++++++++++++ -->

<screen id="start" controller="main.TestNifty">

<layer id="firstLayer" childLayout="center">

<panel id="firstPanelParent" width="100%" height="50%" backgroundColor="#003f" childLayout="vertical">

<panel id="firstPanel1" width="100%" height="50%" backgroundColor="#003a" childLayout="center">

<label id="deepestLabel" text="blue:firstLayerPanel1" align="right"/>

</panel>



<panel id="firstPanel2" width ="100%" height="" backgroundColor="#002a" childLayout="center">

<label id="deepestLabel2" text="blue:firstLayerPanel2" align="right"/>

</panel>

</panel>

</layer>



<layer id="upperLayer" childLayout="center">

<panel id="upperPanel" width="50%" height="100%" backgroundColor="#ff000030" childLayout="center">

<panel id="upperAnotherPanel" width="100%" height="100%" childLayout="center">

<label id="upperLabel" text="red:secondLayerPanel1" align="right"/>

</panel>

</panel>

</layer>



<layer id="uppestLayer" childLayout="center" height="50%">

<panel id="uppestPanel" width="100%" height="100%" childLayout="vertical">

<panel heigth="
"/>

<panel id="uppestAnotherPanel" childLayout="vertical" width="100%" height="73%" backgroundColor="#00ff0030" >

<label id="uppestLabel" text="green:thirdLayerPanel2" valign="bottom" align="right"/>

</panel>

</panel>

</layer>



</screen>

</nifty>



[/xml]

I managed to get multiple layer shown but i still couldn’t get the text done. I tried the ones they did in the tutorial and still no text

If you use the label-tag, then you need to include the standard controls in the xml. Look it up in the nifty tutorials because I cannot remember it right now…



Alternatively you can just use the text-tag. This should also work without the standard controls. At least it works for me… Try als some DebugPanelColors() in the nifty instance so that you don’t have to give the panels all those funny colors :stuck_out_tongue:

kamran



Your problem is simple, the program cannot locate this font.

[java]<text font=“verdana-24-shadow.fnt” text=“Hello World!”

align=“center” valign=“center” />[/java]

(verdana-24-shadow.fnt)



I’ve got the same problem and I dont know what to do.

Maybe we need to locate fonts, but how?

@vawizard

yes you are right vawizard. The program can not locate the font. This is because we did not place the font file in the same folder as the xml file. I figured this out when I was making the hud for my game using only guiNode. I wanted some other font for the game, to do that I had to place the font that I wanted in the interface folder and then load it using

[java]

BitmapFont test = assetManager.loadFont(“Interface/Fonts/textTest.fnt”);

BitmapText HPtext = new BitmapText(test,false);

HPtext.setSize(guiFont.getCharSet().getRenderedSize());

HPtext.setColor(ColorRGBA.Blue);

HPtext.setText(“HP” + maxHP);

HPtext.setLocalTranslation(0,HPtext.getLineHeight(),20);

[/java]

I think for the Nifty you only have to place the font file in the same folder as .xml to work. I haven’t tried it yet but will soon after handling some other stuff for the game.

K Out!