Hey, I'm making a State Based Platform Game in Slick2D, and decided to use TWL as an easier way of adding GUI elements. However, upon trying to add a button to my Title Screen, I have been heavily confused by the examples. I think it's because the examples are not StateBasedGames, and so they are just stand-alone classes that can extend Widget, and because my BasicTWLGameState cannot extend widget, I'm not too sure how to add a button.
Can anyone explain to me how I get a button onto my screen from a class that extends BasicTWLGameState? I've already got my theme set up!
Here's the main method in my TitleScreen class.
Code:
public class TitleScreen extends BasicTWLGameState {
public static void main(String[] args) throws SlickException, IOException {
try {
LWJGLRenderer renderer = new LWJGLRenderer();
Widget widget = new Widget();
GUI gui = new GUI(widget, renderer);
TitleScreen title = new TitleScreen();
ThemeManager theme = ThemeManager.createThemeManager(widget.getClass().getResource("themeTest.xml"), renderer);
gui.applyTheme(theme);
while(!Display.isCloseRequested() && !title.quit) {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
gui.update();
Display.update();
}
gui.destroy();
theme.destroy();
} catch (LWJGLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Display.destroy();
}
I tried to do the same as in the examples, but when I run the game I get this error
Code:
Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glGetInteger(GL11.java:1353)
at de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer.syncViewportSize(LWJGLRenderer.java:224)
at de.matthiasmann.twl.renderer.lwjgl.LWJGLRenderer.<init>(LWJGLRenderer.java:125)
at TitleScreen.main(TitleScreen.java:28)
Any help would be greatly appreciated, thanks!
Note: As you can probably tell, I'm not an expert!