Black Screen Using NiftyGUI w/ Application and AppState

Hi,



I’m an older JME1/2 developer who is trying to start using JME3 (I think what you have done with it is AWESOME by the way).



I’ve installed the jMonkeyPlatform and have created an XML file from the tutorials on NiftyGUI. I am trying to build an Application and here is the very top overview of what I want



+Main (extends Application, has many AppStates)

  • MainMenuState (extends AppState)

    … others including Play and About AppStates …



    Here is my XML file for my GUI:

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

    <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">

    <screen id="start" controller="com.trussellgroupllc.legionaire.gui.MainMenuController">

    <useControls filename="nifty-default-controls.xml" />

    <layer id="layer" backgroundColor="#000000" childLayout="center">

    <panel id="bgPanel" height="100%" width="100%" align="center" valign="center" style="nifty-panel-simple">



    </panel>



    <panel id="buttonpanel" height="80%" width="40%" align="center" valign="center" style="nifty-panel">

    <control id="startGameBtn" label="Start Game" />

    <control id="settingsBtn" label="Settings" />

    <control id="aboutBtn" label="About Legionaire" />

    <control id="quitBtn" label="Quit Legionaire" />

    </panel>

    </layer>

    </screen>

    </nifty>

    [/xml]



    Here is my Application extension:

    [java]

    package com.trussellgroupllc.legionaire;



    import com.jme3.app.Application;

    import com.jme3.system.AppSettings;

    import com.jme3.system.Timer;

    import com.trussellgroupllc.legionaire.appstates.MainMenuState;

    import com.trussellgroupllc.legionaire.logging.LoggingManager;



    /**
  • test
  • @author normenhansen

    */

    public class Main extends Application {



    MainMenuState mainMenuState;



    public static void main(String[] args) {

    Main app = new Main();

    app.start();

    }



    @Override

    public void start() {

    settings = new AppSettings(true);

    settings.setResolution(800,600);

    settings.setFullscreen(false);

    super.start();

    }



    @Override

    public void initialize() {

    super.initialize(); //Call Super’s Init

    guiViewPort.setEnabled(true);



    LoggingManager.getInstance().logStd("+=== Application Initialized ===+");

    LoggingManager.getInstance().logStd(“t(TrussellGroup, L.L.C. v0.01)”);



    mainMenuState = new MainMenuState();

    stateManager.attach(mainMenuState);//Load our Main Menu into the AppStateManager

    }



    @Override

    public void update() {

    super.update();

    float tpf = timer.getTimePerFrame();



    stateManager.update(tpf);

    stateManager.render(renderManager);



    renderManager.render(tpf);

    }



    @Override

    public void destroy() {

    LoggingManager.getInstance().shutdown();

    super.destroy();

    }



    public Timer getTimer() {

    return timer;

    }

    }

    [/java]



    And my AppState extension:

    [java]

    package com.trussellgroupllc.legionaire.appstates;



    import com.jme3.app.Application;

    import com.jme3.app.state.AppState;

    import com.jme3.app.state.AppStateManager;

    import com.jme3.math.Vector3f;

    import com.jme3.niftygui.NiftyJmeDisplay;

    import com.jme3.renderer.RenderManager;

    import com.trussellgroupllc.legionaire.logging.LoggingManager;

    import de.lessvoid.nifty.Nifty;



    /**

    *
  • @author Tyler

    */

    public class MainMenuState implements AppState {



    Application appRef;

    AppStateManager stateManagerRef;



    boolean fullinit = false, active = false;

    String gameTitleText, aboutText, startBtnText, stgsBtnText, quitBtnText, abtBtnText;



    NiftyJmeDisplay niftyDisplay;

    Nifty nifty; //Our Main GUI Control



    public void initialize(AppStateManager stateManager, Application app) {

    this.appRef = app;

    this.stateManagerRef = stateManager;



    gameTitleText = “Leginonaire”;

    aboutText = “TrussellGroup, L.L.C. v0.01”;

    startBtnText = “Start New Game”;

    stgsBtnText = “Options”;

    quitBtnText = “Quit Legionaire”;

    abtBtnText = “About Legionaire”;



    niftyDisplay = new NiftyJmeDisplay(

    app.getAssetManager(), app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort());

    nifty = niftyDisplay.getNifty();

    nifty.fromXml(“Interface/MainMenuGui.xml”, “start”);

    app.getGuiViewPort().addProcessor(niftyDisplay);



    setActive(true);

    fullinit = true;

    }



    public boolean isInitialized() {

    return fullinit;

    }



    public void setActive(boolean active) {

    if (!isInitialized()) {

    System.err.print(“MainMenuState could not be activated because it is not initialized.”);

    } else {

    this.active = true;

    }

    }



    public boolean isActive() {

    return this.active;

    }



    public void stateAttached(AppStateManager stateManager) {

    LoggingManager.getInstance().logStd(“MainMenuState attached to AppStateManager.”);

    }



    public void stateDetached(AppStateManager stateManager) {

    LoggingManager.getInstance().logStd(“MainMenuState removed from AppStateManager.”);

    }



    public void update(float tpf) {

    if(this.active)

    nifty.update();

    }



    public void render(RenderManager rm) {}



    public void postRender() {}



    public void cleanup() {

    nifty.exit();

    }

    }

    [/java]



    But I just see a black screen. I’m sure it’s something that I’m not rendering, but like I said I’m unsure because I haven’t used much JME3. I looked through all of the Documentation, but there just wasn’t enough to get me started. Thanks, guys!

Hmmm… Cant try it atm but it looks ok… I suggest a) trying with the default niftygui xml file (New File…) and b) try using a SimpleApplication base.

overhere:

[xml]

<control id=“startGameBtn” label=“Start Game” />

<control id=“settingsBtn” label=“Settings” />

<control id=“aboutBtn” label=“About Legionaire” />

<control id=“quitBtn” label=“Quit Legionaire” />

[/xml]



You are telling nifty to add controls without telling nifty what kind of controls. This may be what’s causing the problem. Without being able to test it atm. I can’t be 100% sure though.



If you need buttons, try adding name=“button” to the control.

1 Like

ractoc is right, the name attribute is required for the control tag.



@Trussell:

the Nifty instance supports optional xml validation. You can just call: nifty.validateXml() with the xml file to validate and it will probably complain about incorrect or missing tags! :slight_smile:



@Normen:

This is something the code completion in jMP already provides I think. This time it’s in the XSD:



[xml] <xs:complexType name=“controlType”>

<xs:complexContent>

<xs:extension base=“elementType”>

<xs:attribute name=“name” type=“xs:string”></xs:attribute>

<xs:attribute name=“onChange” type=“xs:string”></xs:attribute> <!-- this is not supported anymore in Nifty 1.3 -->

<xs:anyAttribute processContents=“skip” namespace="##any" />

</xs:extension>

</xs:complexContent>

</xs:complexType>[/xml]



That “onChange” has to be removed. It’s not supported any more. I’ve missed that. D’oh!