Beginner questions

Hi,

at first i would like to say im totally new to Jme3, i have programmed in java for about 2 1/2 years now and wanted to make a simple game ^^.A game typically starts with an Menu and as i read trought a LOT tutorials/ wikis / ebooks /youtube videos etc.

i havent seen a good tool to edit the xmls for nifty gui.

This led me to make the nifty gui in Java code and as for now im completly frustrated and confused…



I cant find any tutorials that go beond the basic things like display a text or display an image.

so far i found this:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:nifty_gui_java_layout

and

Download nifty-gui from SourceForge.net







The problem now is that in the pdf not everything is explained in both ways (mostly only in xml).

can anyone lead me to the right direction?





Actually im facing 3 problems:

1:

Text Views dont react if i click them …



my code:

Main class:

[java]

@Override

public void simpleInitApp() {

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(

assetManager, inputManager, audioRenderer, guiViewPort);

Nifty nifty = niftyDisplay.getNifty();

guiViewPort.addProcessor(niftyDisplay);

flyCam.setDragToRotate(true);



nifty.loadStyleFile("nifty-default-styles.xml");

nifty.loadControlFile("nifty-default-controls.xml");

nifty.addScreen("menu", new ScreenBuilder("menu") {{

controller(new MenuController());



// <layer>

layer(new LayerBuilder("Background") {{

childLayoutAbsolute(); // layer properties, add more…

// //

//// // <panel>



// //

//// // GUI elements

image(new ImageBuilder() {{

filename("Interface/Res/menu_overlay2.png");

x("0");

y("0");

}});



image(new ImageBuilder() {{

filename("Interface/Res/menu_Logo.png");

x("1500");

y("50");

}});

// //

//// //… add more GUI elements here

// //



//// // </panel>

}});

//// // </layer>



layer(new LayerBuilder("foreground") {{

childLayoutAbsolute();

backgroundColor("#0000");



// // <panel>

panel(new PanelBuilder() {{

childLayoutAbsolute(); // panel properties, add more…

// add text

text(new TextBuilder() {{

text("Singleplayer");

font("Interface/Fonts/Default.fnt");

height("100%");

width("100%");

x("200");

y("200");

visibleToMouse(true);

interactOnClick("Singleplayerclick()");

}});



text(new TextBuilder() {{

text("Multiplayer");

font("Interface/Fonts/Default.fnt");

height("100%");

width("100%");

x("200");

y("400");

visibleToMouse(true);

interactOnClick("Multiplayerclick()");

}});



text(new TextBuilder() {{

text("Options");

font("Interface/Fonts/Default.fnt");

height("100%");

width("100%");

x("200");

y("600");

visibleToMouse(true);

interactOnClick("Optionsclick()");

}});



text(new TextBuilder() {{

text("Quit");

font("Interface/Fonts/Default.fnt");

height("100%");

width("100%");

x("200");

y("800");

visibleToMouse(true);

interactOnClick("Quitclick()");

}});



}});

// // </panel>

}}); // layer added

}}.build(nifty));

this.nifty.gotoScreen("menu");

}

[/java]





controller class:



[java]package de.kullorki;



import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.builder.ImageBuilder;

import de.lessvoid.nifty.builder.LayerBuilder;

import de.lessvoid.nifty.builder.PanelBuilder;

import de.lessvoid.nifty.builder.PopupBuilder;

import de.lessvoid.nifty.builder.ScreenBuilder;

import de.lessvoid.nifty.builder.TextBuilder;

import de.lessvoid.nifty.controls.TextField;

import de.lessvoid.nifty.controls.button.builder.ButtonBuilder;

import de.lessvoid.nifty.elements.render.TextRenderer;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;

import de.lessvoid.nifty.tools.SizeValue;



public class MenuController implements ScreenController {

private Nifty nifty;

private Screen screen;

@Override



public void bind(Nifty newNifty, Screen newScreen) {

nifty= nifty;

screen = newScreen;

}

@Override

public void onStartScreen() {

}

@Override

public void onEndScreen() {

}



public void Quitclick() {

System.out.println("Quit Klick YAY");



}

public void Optionsclick() {

System.out.println("KLICK");

}





public void Multiplayerclick() {

System.out.println("multiplayer klick");

}







public void Singleplayerclick() {

System.out.println("singleplayer klick");

}

}[/java]







2. how to make effects in java code without xml?



for example i found this:

[xml]<onHover name="textSize" maxSize="120%">

<hover hoverFalloffType="linear"

hoverFalloffConstraint="both"

hoverWidth="200%"

hoverHeight="200%" />

</onHover>[/xml]

how to transfer it into this textview?



[java] text(new TextBuilder() {{

text("Options");

font("Interface/Fonts/Default.fnt");

height("100%");

width("100%");

x("200");

y("600");

visibleToMouse(true);

interactOnClick("Optionsclick()");

}});[/java]





3.

For example i tried to install OgreXml several times but Blender 2.62 doesnt show me the option to export ogre xml



I have searched for 4 full days now and cant find a solution to this.

Can anyone help me pls? :cry:

If I may give some input on your code, I’d make you aware that you have 4 text elements with width=“100%” and height=“100%” in a panel without a size. How do they know how big they should be? And do you really want all of them to cover their entire parent element?

Try giving your layer and panel a width and height and give the text elements appropriate widths and heights in relation to their parents.



Usually in Java, methods use “camelcase”, starting with a lower case character and having an upper case character at the start of each new word in the method name, e.g. singlePlayerClick rather than Singleplayerclick. Using this convention makes it easier to tell apart the different parts of the program.



As for adding effects to builders you can use the builder.onHoverEffect, builder.onClickEffect etc. methods. See the javadoc or autocompletion/suggestions in your IDE.

2 Likes

Thanks this helped a Lot :slight_smile:





My TextViews do what they are supposed to :wink:



But i cant get effects working

I Use Eclipse 3.7

Java 7

and

Jme 3 latest nightly build ( jME3_2012-03-04.zip 04-Mar-2012 00:20 82M )



for example:

[java] text(new TextBuilder() {{

text("Singleplayer");

font("Interface/Fonts/Default.fnt");

height("80px");

width("200px");

new EffectBuilder("hover"){{

length(1000);

startDelay(0);

inherit(true);

post(false);

}};





interactOnClick("Singleplayerclick()");



}});[/java]

i dont think i did this right (its not working), because i have not found any example to effects in code, only in xml :frowning:

It’s almost right, you just need to use the setter method on the builder instead of creating a new EffectBuilder inside it (that won’t be used). Also, for hover effects you should use a HoverEffectBuilder. Oh and the parameter you pass to the EffectBuilder/HoverEffectBuilder is the effect name (like move, textSize etc.).

Something like this:

[java]text(new TextBuilder() {{

text(“Singleplayer”);

font(“Interface/Fonts/Default.fnt”);

height(“80px”);

width(“200px”);

onHoverEffect(new HoverEffectBuilder(“textSize”) {{

length(1000);

startDelay(0);

inherit(true);

post(false);

hoverFalloffType(Falloff.HoverFalloffType.linear);

hoverFalloffConstraint(Falloff.HoverFalloffConstraint.both);

hoverWidth(“200%”);

hoverHeight(“200%”);

}});

interactOnClick(“Singleplayerclick()”);

}});[/java]

Note that the above code might not be 100% correct, as I just typed it here with help of the javadoc: Nifty Core 1.3.1 API.

2 Likes

Wow… just WOW Tumaini : You are my Hero :o


  1. Your code is 100 % correct and working !


  2. i have been searching for this Javadoc an eternity !!



    Thanks a LOT :slight_smile: