Slick Forums

Discuss the Slick 2D Library
It is currently Mon May 20, 2013 5:04 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Mar 28, 2012 11:28 pm 
Offline

Joined: Sun Mar 04, 2012 7:35 am
Posts: 14
At what point can I use TWLStateBasedGame.getGUI()? I'm trying to set some image overlays for my button hotbar, but getGUI() is still null at this point. Is there a different function I can use for this kind of initialization after the GUI is instantiated?

Code:
public class MyGameplayState extends BasicTWLGameState {
  private Button[] m_hotbar = new Button[10];
  ...

  @Override
  protected void createRootPane() {
    ....
    // set overlay images for my buttons
    Renderer renderer = m_game.getGUI().getRenderer();
    for (int i = 0; i < m_hotbar.length; ++i) {
      String path = "icons/" + m_hotbarActions[i].getIconName();
      try {
             Texture texture = renderer.loadTexture(new File(path).toURI().toURL(), "COLOR", "LINEAR");
             de.matthiasmann.twl.renderer.Image img = texture.getImage(0, 0, texture.getWidth(), texture.getHeight(), de.matthiasmann.twl.Color.WHITE, false, Texture.Rotation.NONE);         
             m_hotbar[i].setOverlay(img);
       } catch(Exception exc) {
          LOGGER.error("Failed to load hotbar image: " + exc);
       }
    }
  }
}


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

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:  
cron
Powered by phpBB® Forum Software © phpBB Group