Hi,
I’m wondering how I get a own drawn image, or an edited image into nifty on-the fly changed outside simpleInitApp().
My problem is, that this works only in simpleInitApp() (imageMap is my edited image):
NiftyImage nimg = new NiftyImage(nifty.getRenderEngine(), new RenderImageJme(new Texture2D(imageMap)));
Element niftyElement = nifty.getCurrentScreen().findElementByName("monmapimage");
// swap old with new image
niftyElement.getRenderer(ImageRenderer.class).setImage(nimg);
This changes the image in nifty, but only with loaded images:
NiftyImage nimg= nifty.getRenderEngine().createImage(nifty.getCurrentScreen(),mapFile, false);
Element niftyElement = nifty.getCurrentScreen().findElementByName("monmapimage");
// swap old with new image
niftyElement.getRenderer(ImageRenderer.class).setImage(nimg);
so how to change edited images in nifty outside simpleInitApp()?
Yup, it seems that some caching is going (or maybe nifty simply don’t notices the updates in my Texture2D ‘imageMap’).
Cause my code works as long as I call my method inside simpleInitApp().
If I call the first code example from somewhere (for example from a buttonclick in game), then only the old image is shown, not my changed image.
Maybe I need to put my update somehow in simpleUpdate()? Or is there something like niftyElement.invalidate(), to let nifty know I changed the image?
Anyway what GUIs do you use? I often find nifty a bit clumbsy, so maybe other GUIs are worth to test (toneGui?, HeroDex GUI?)?
If nifty is configured to use batching (I d’ont remember how you do this, but you probably know it if you do it), it generates a texture atlas with all your images.
So it’s not really using your image afterward so if it changes, Nifty doesn’t know it.
Without batching though, it should work.
I call the method now from simpleUpdate(float tpf), same problem.
could it be the problem that I use an loaded image and then draw on it?
When I call my method from simpleInitApp(), all works like expected.
No I have not enabled a special caching, it’s plain nifty.
Texture texRad, monMap;
Image imageMap;
...
texRad = assetManager.loadTexture(radarFile);
imageMap = texRad.getImage();
...
manipulatePixel(imageMap, x, y, color, true); //set border in owner color
...
NiftyImage nimg = new NiftyImage(nifty.getRenderEngine(), new RenderImageJme(new Texture2D(imageMap)));
Element niftyElement = nifty.getCurrentScreen().findElementByName("monmapimage");
// swap old with new image
niftyElement.getRenderer(ImageRenderer.class).setImage(nimg);
In theory, i fit’s a batching issue, then it works only from simpleInit because nothing has been drawn yet. Once something is drawn then it’s batched and somehow that has to be retriggered.
I know almost nothing about nifty so I’m just guessing. For example, I don’t know why resetting the image wouldn’t cause a rebatch.
…there is no such setUpdateNeeded() in your link and none in the ‘nifty-gui-the-manual-1.3.2.pdf’ I downloaded some time ago, nor did I found that topic there (Besides it’s easier when one already knows the answer, makes lots easier what to search for).
I’m not sure if it’s ‘dead’ wrong. I guess the most people here in forum search first, before asking, so did I.
So where did you see a link in your post that would be the answer on this threads-topic?
Besides knowing the anwer but writing only ‘RTFM’-posts wastes both, the readers and the posters time.
Hi, if you are having problems with the nifty GUI manual and wiki, I recommend downloading the source release from https://github.com/void256/nifty-gui/releases .
Nifty 1.3.2 is bundled with jMonkey.
Many people hate nifty, but after seeing many UI frameworks, I actually like it. A lot.
Despite the problematic documentation, it’s either NiftyGUI or self-written UI.
Note: anyone contemplating that route should at least start with Lemur. It’s made to be modular and parts of it can be reused directly (mouse handling, input management, etc.) without starting from scratch. Also, it’s implementation is very lightweight and JME-friendly and designed for easy composition/extension.