Hi.
I'd like to be able to simply store and render an image. How would I do this in TWL? It seems that no image class is designed simply for rendering images, and there exists no documentation for the constructors of the classes that do exist - which is fine, since I can look at the source code. I can't/don't want to use:
- GridImage (it seems to store an array of images- overkill)
- TextureArea (there is no documentation whatsoever on how to instantiate a TextureArea object - one of the parameters LWJGLTexture itself requires another LWJGL object as a parameter)
- AnimatedImage (I want a static image)
I tried creating my own class:
Code:
package gui;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import de.matthiasmann.twl.Color;
import de.matthiasmann.twl.Widget;
import de.matthiasmann.twl.renderer.AnimationState;
public class SimpleImage extends Widget implements de.matthiasmann.twl.renderer.Image {
private Image slickImage;
SimpleImage(String fileName) throws SlickException {
this(fileName, null, false);
}
SimpleImage(SimpleImage rhs) {
super(rhs.getAnimationState(), false); // Should this be true or false?
slickImage = rhs.slickImage.copy();
setInnerSize(slickImage.getWidth(), slickImage.getHeight());
}
SimpleImage(String fileName, de.matthiasmann.twl.AnimationState animState, boolean inherit) throws SlickException {
super(animState, inherit);
slickImage = new Image(fileName);
setInnerSize(slickImage.getWidth(), slickImage.getHeight());
}
@Override
public void draw(AnimationState as, int x, int y) {
draw(x, y);
}
@Override
public void draw(AnimationState as, int x, int y, int width, int height) {
slickImage.draw(x, y, 0, 0, width, height);
}
public void draw(int x, int y) {
slickImage.draw(x, y);
}
@Override
public de.matthiasmann.twl.renderer.Image createTintedVersion(Color color) {
// Do nothing for now...
return new SimpleImage(this);
}
}
But I get some error regarding recursively adding widgets to the GUI:
Quote:
Sun Oct 30 10:54:38 CST 2011 ERROR:null
java.lang.NullPointerException
at de.matthiasmann.twl.Widget.recursivelyAddToGUI(Widget.java:2341)
at de.matthiasmann.twl.Widget.recursivelyAddToGUI(Widget.java:2350)
at de.matthiasmann.twl.Widget.recursivelyAddToGUI(Widget.java:2350)
at de.matthiasmann.twl.Widget.insertChild(Widget.java:1214)
at de.matthiasmann.twl.GUI.setRootPane(GUI.java:247)
at twlslick.TWLStateBasedGame.setRootPane(TWLStateBasedGame.java:128)
at twlslick.BasicTWLGameState.enter(BasicTWLGameState.java:80)
at org.newdawn.slick.state.StateBasedGame.update(StateBasedGame.java:261)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:663)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at poo.Application.main(Application.java:32)
Sun Oct 30 10:54:38 CST 2011 ERROR:Game.update() failure - check the game code.
org.newdawn.slick.SlickException: Game.update() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:669)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:411)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:321)
at poo.Application.main(Application.java:32)
Cheers.