I am trying to change a nifty image.
When I follow the tutorial, it doesn’t work.
Java Modifies Nifty Elements and Events
You can also alter the appearance and functions of your nifty elements from Java. Make certain that the element that you want to alter has its id=“name” attribute set, so you can identy and address it.
Here’s an example of how to change an image called playerhealth:
// load or create new image
NiftyImage img = nifty.getRenderEngine().createImage(“Interface/Images/face2.png”, false);
// find old image
Element niftyElement = nifty.getCurrentScreen().findElementByName(“playerhealth”);
// swap old with new image
niftyElement.getRenderer(ImageRenderer.class).setImage(img);
And I use this line:
[java]
NiftyImage img = nifty.getRenderEngine().createImage(“Interface/Images/face2.png”, false);
[/java]
The SDK says there is no method with that parameters, there is a method with name createImage but the parameters should be: createImage(Screen screen, String name, boolean filterLinear)
Error: Method createImage in interface NiftyRenderEngine can not be applied to given types
The nifty variable is just a Nifty object.
The image in the xml file I want to change has id inventory-image
When I use createImage(Screen, String, boolean) my SDK doesn’t give any errors. But when the image becomes changed at runtime, it throws exceptions and there is no visible result.
Problem solved! nifty was changing screen (or something) between creating the image and setting the new image to the ImageRenderer. It was just an error in the sequence.