Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 25, 2013 11:27 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Apr 04, 2012 6:39 pm 
Offline

Joined: Wed Apr 04, 2012 6:26 pm
Posts: 2
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!


Top
 Profile  
 
PostPosted: Wed Apr 04, 2012 8:18 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1173
When using TWLStateBasedGame (see the TWL wiki) it creates a RootPane class (in the provided code it's a subclass of DesktopArea) for each state where you can add your button and other widgets.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group