NiftyGUI Image Centering Problems

I was going to post this in the NiftyGUI forums, but I’ll just post here in hopes that someone else in the jme3 community has experienced this problem. My issue is that it seems NiftyGUI is unable to correctly center images according to “center” layout.

Here is my screen xml definition:

<screen id=“start” controller=“client.MainScreenController”>

<layer id=“layer” backgroundColor="#000000ff" childLayout=“center”>

<panel id=“logo” backgroundColor="#0000" height=“40%” width=“80%” align=“center” valign=“center” childLayout=“center”>

<image id=“image” filename=“Interface/logo.png”></image>





My controller could really be any screen controller, as it doesn’t do anything (prints debugging info is all) and the image could be any image. My image is like 191x506 pixels.

When I use different resolutions, my image is not always centered on the screen. Also, when I actually specify the image dimensions, by doing this:

<image id=“image” filename=“Interface/logo.png” height=“191” width=“506”></image>

The image no longer shows up at all. I have no idea how NiftyGUI is calculating the “center” but it seems flawed. For example, when I switch the dimensions of my logo panel to the same dimensions of the image, it centers the (0,0) (upper left) coordinate of the image at the center of the screen. It seems to not account for offsetting by imageHeight/2 and imageWidth/2 for correct centering.

Anyone else seen this problem, or know of a workaround?

Why isn’t this site letting me post xml snippets?

It seems there is a bug with xml tags i tried with <code> but doesn’t look better.

so i changed < by & l t ; so everyone can see the code (indentation is lost btw :p)

For your problem try to set the align=“center” on the image tag.

For the height and width pb i think you have to specify “px” but not sure. try height=“191px”

Thanks Nehon.

Doing align=“center” valign=“center” on the image element itself worked.