Slick Forums

Discuss the Slick 2D Library
It is currently Sun Dec 17, 2017 6:11 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Thu Oct 10, 2013 5:09 pm 
Offline

Joined: Thu Oct 10, 2013 4:50 pm
Posts: 2
Hey,

I'm trying to create a GUI for my game using slick and TWL. However, the issue I'm facing is that even though I'm using event-based inputs and the TWLInputAdapter available on the wiki, both slick and TWL will receive inputs. Here's the related pieces of code:

Code:
public void init(GameContainer container) throws SlickException {
        gui = new GUI(root, lwjglRenderer);
        twlInputAdapter = new TWLInputAdapter(gui, container.getInput());
        container.getInput().addPrimaryListener(twlInputAdapter);
}

public void update(GameContainer container, int delta){
      twlInputAdapter.update();
         
      if(container.getInput().isKeyPressed(Input.KEY_ENTER)){
         doStuff();
      }
      
      if(container.getInput().isMousePressed(Input.MOUSE_LEFT_BUTTON)){
         doStuff();
      }
}


From overriding methods in the TWLInputAdapter class, I could determine that apparently the consume() call does nothing even if the GUI reports the event as handled. I did google the issue, however, there is only like 5 threads on the subject and most of them went unresolved. Since I'm running out of ideas myself - do you guys have any advice for me?

Edit: Okay, after some more researching I found out that I'm probably not supposed to use the "isPressed" methods in addition to the "isDown" ones either. This puts me in a dilemma, though, as those are the only options I get from container.getInput(). Should I try to work something out with the methods provided by TWLInputAdapter? Seeing as they return voids, how would I check for that in my game loop?


Top
 Profile  
 
PostPosted: Fri Oct 11, 2013 5:17 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
Use the input event handling methods in your GameState or provide a custom TWL root widget (see GUI constructor) and overrides it's handleEvent() method.

The current key state querying APIs are not usable as it's not possible to "consume" the current state - you can only consume events.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Sat Oct 12, 2013 10:43 pm 
Offline

Joined: Thu Oct 10, 2013 4:50 pm
Posts: 2
Thanks for the quick reply! The issue is resolved now - here's where i went wrong: I assumed i could only use slicks container.getInput() Input System, which obviously only provided me with state-based methods such as isKeyPressed and isMouseDown. The solution was to implement my own slick.KeyListener and slick.MouseListener, and add those to the Input in addition to the TWLInputAdapter.

Now in hindsight i know that this is probably excactly how the adapter is meant to be used - however, for some reason I found it quite hard to get my head around that. And yes, i do feel a little stupid right now. :) Anyway, hope this helps anyone facing the same issue!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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:  
cron
Powered by phpBB® Forum Software © phpBB Group