Slick Forums

Discuss the Slick 2D Library
It is currently Mon May 20, 2013 7:50 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: TWL and Input Events
PostPosted: Sun Sep 09, 2012 10:41 am 
Offline

Joined: Sun Sep 09, 2012 10:11 am
Posts: 1
Hi,

I'm using TWL for my GUI and I really like it. But now I've a problem with the Event handling. Searching in the forum I already found similar questions but I wasn't able to solve it.

I'm using TWLStateBasedGame as explained in the Wiki (http://wiki.l33tlabs.org/bin/view/TWL/Integrating+TWL+into+StateBasedGame). I draw some stuff in the render method and the TWL GUI is drawn upon that. Now I want the TWL GUI to consume its events and my own stuff to react to the remaining events.

Using input.isMousePressed(Input.MOUSE_LEFT_BUTTON) is obviously wrong because it gets all the events. I now replaced the TWLInputForward class from the StateBasedGame example with TWLInputAdapter class from the other example (http://wiki.l33tlabs.org/bin/view/TWL/Using+TWL+with+Slick) and changed the Code in TWLStateBasedGame to

Code:
Input input = getContainer().getInput();
//TWLInputForwarder inputForwarder = new TWLInputForwarder(gui, input);
TWLInputAdapter inputAdapter = new TWLInputAdapter(gui, input);
input.addPrimaryListener(inputAdapter);


Now I added a listener in my GameState:

Code:
@Override
public void init(GameContainer gc, StateBasedGame game)
         throws SlickException {
   gc.getInput().addListener(new InputAdapter() {
      @Override
      public void mousePressed(int button, int x, int y) {
         System.err.println("mouse pressed");
      }
   });
}


The event handling for the GUI still works but I don't receive any mousePressed events. What am I doing wrong?

Thanks for your help!


Top
 Profile  
 
 Post subject: Re: TWL and Input Events
PostPosted: Sun Sep 09, 2012 2:21 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
The Slick input system is not really good to handle such kind of things. The TWLStateBasedGame calls the mousePressed & co methods of your state for any unhandled event. So it is best to either use these methods, or use TWL directly to handle events. But you can't register additional Slick input listener, as I found no way to make these work reliable.

_________________
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