I am new to JME3 game engine but I know Android XML GUI layouts pretty good. I have a simple layout here and I cant figure out what is wrong. Here is my XML code:

<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd"

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

<screen id="start" controller="com.jasoncrosby.game.farkle.gui.MenuScreenGui">
    <layer id="layer" backgroundColor="#66CD00" childLayout="center">
        <panel id="panel" align="center" valign="center" childLayout="center" visibleToMouse="true">
            <image filename="Textures/wood_floor.png" height="95%" width="95%"/>

            <panel id="panel" align="center" valign="center" childLayout="center" visibleToMouse="true">
                <text text="test" font="Interface/Fonts/Eraser.fnt"></text>

Everything works well until I get to displaying the text. I have tried different alignments and tried moving the text into different panels but no matter what I do the text is never in the center of the screen. It's always in the upper left corner, so far I can only see the lower right part of the text. How can I center the text element in the center of the screen?

  • \$\begingroup\$ Welcome to GDSE! Sorry, but it is too localized (you don't really ask how to make a nifty GUI layout, you ask to find a specific bug) for the site; please read FAQ: gamedev.stackexchange.com/faq \$\endgroup\$ – Markus von Broady Oct 18 '12 at 20:24
  • 1
    \$\begingroup\$ @MarkusvonBroady Given Byte56's answer this looks like an issue a lot of new JME3 users would run into (it happens often enough in HTML and other similar layout engines). I think this is a helpful cannon question. \$\endgroup\$ – doppelgreener Oct 19 '12 at 0:10
  • \$\begingroup\$ Agreed. If the XML presented was very complex or specific to the OPs game, then it would be too localized. But the XML presented is very generalized and likely pretty common starting XML. \$\endgroup\$ – MichaelHouse Oct 19 '12 at 1:25

I believe the problem you're having is that neither your layer, nor your panel are the size of screen. They are both very small in the upper left (which I believe is the default). So centering your image just puts them in the center of a very small rectangle in the upper left.

If you want to center your text on screen, you need to make a panel the size of the screen and then center it in that panel.

  • \$\begingroup\$ Thanks everyone for your assistance that helped me with my problem. \$\endgroup\$ – Jason Crosby Oct 19 '12 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.