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!