Nifty GUI TextureAtlas for Inventory-Items

Hi everyone :wink:

I am currently making an inventory system and therefore need to display some item icons to the user (similar to minecraft inventory). The GUI is made with Nnfty so I want to use nifty for those inventory slots too. Logically, I want to use a TextureAtlas for storing all item icons but unfortunately I couldnĀ“t find any way of setting a nifty components (image or background-image of a panel) image via a TextureAtlas. To me it looks like if it would only support a String for a single image.

Has anyone experienced the same problem?

Not sure if you mean the actual class TextureAtlas. If so, you could probably set the texture like this:

Element icon = inventory.findElementById("Icon1234");
ImageRenderer renderer = icon.getRenderer(ImageRenderer.class);
renderer.setImage( new NiftyImage(_nifty.getRenderEngine(), new RenderImageJme(atlas.getAtlasTexture("DiffuseMap")) );

The latest version of Nifty (1.4? the one that comes with the jme 3.1 alpha) supports automatic generation of an atlas. It uses one single texture that is populated with all the images that you add. You have to use a certain constructor of NiftyJmeDisplay to activate the atlas. But AFAIK this prevents you from using jme-generated textures (like from a viewport that is rendered to a texture).

You can also draw your atlas yourself and then use something like:

backgroundImage="Textures/gui/atlas.png" imageMode="subImage-resize:1,1,40,191,19,2,19,1,19,2,19,179,19,2,19,11"

Different image modes are covered in the manual.

Sry for my late reply. I googled Nifties imageModes, but I couldnĀ“t find a useful documentation. What do these numerical parameters mean? Is there somewhere the source rectangle I want to use of the given texture, or what do they mean?
Additionally, I appreciate every source for nifties image modes.

Thanks :slight_smile:

Here is a link to the nifty gui manuals:
Check the chapter ā€œimagemode propertyā€.

Thanks IĀ“ll look into it :wink:

Ok that really solved my problems, Nifty even has a sprite mode :smiley:
Definitely a big thanks for that :wink: