[LibGDX]Entity Framework and Input - Best approach?

So I have been re-working a project that has been on the back-burner since November and decided to go with an Entity Framework for a nice and maintainable code.

The entity system I am using is Ashley and it is optional when creating a LibGDX project. Just as well, as I was going to go with Artemis until I seen this :P.

I am at the stage now where I want to take input and process the player with it, however I am not quite sure how to do this, from a design perspective.

I have a system for the player, which will handle the management of states by swapping components about (as I read, this is the best way to handle states). I am not quite sure how do handle input.

I could easily add a bunch of if blocks and constantly poll input, however the input will be received using the UI (Scene2D).

What is the best approach to this? Any ideas?

Perhaps you should make a InputManager class, that maintains a list of registered InputListeners?
Then make a Entity System whitch implements InputListener and registers itself to the InputManager.In the update method, find the player entity by a IDComponent (empty class ex. PlayerTAGComponent extends Component), then do your calculations.
If you need any help with the actual implementation, i can help :slight_smile:

This is sort of what I have at the moment.

I am using components to swap states about, what I have at the moment is you press the space key and if the entity has a GroundedComponent, it gives the entity a JumpComponent, the JumpSystem then uses data from that component to propel the entity upwards, then removes the GroundedComponent, the JumpComponent and adds an AirborneComponent.

All this is fine and dandy, but you can’t really poll for input from Scene2D like I am doing now. Say you press left, change the data in the VelocityComponent, which is then handled by the MotorSystem.

However, if you know what Scene2D is like, it has every button you add to the stage take a callback. I don’t want to have to make a ton of anonymous classes in a system (the button shouldn’t even be in the system for a starter).

So Scene2D has no knowledge of any of the components of an entity, I think I may be missing something simple here :S.

So from what i understand, the buttons are on-screen, right?
And your problem is that you cant poll the button state from within the entity system… right?
So maybe add some booleans/action variables to the InputManager class that hold the data for the specific action. F.ex Action moveLeftAction = new Action(Key primary, Key secondary);
Because the InputManager is a InputListener itself, you would still be able to modify the action states by keyboard (when compiling for desktop).
In the callback classes you could override that behavior by manually setting the action on/off state.
Whenever you pass the InputManager to the Entity System and GUI System in the constructor, or make the InputManager a static singleton is up to you.