Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (775)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX]Entity Framework and Input - Best approach?  (Read 2791 times)
0 Members and 1 Guest are viewing this topic.
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Posted 2015-03-18 14:05:24 »

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  Tongue.

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?

"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Offline Olo

JGO Coder


Medals: 15
Projects: 3
Exp: 5 years


Metaphysical solipsism AFFIRMS your existence


« Reply #1 - Posted 2015-03-18 19:29:25 »

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 Smiley

-Can you fix it?
-No, I can't. But I can bypass it with one of these.
Offline Gibbo3771

JGO Kernel


Medals: 128
Projects: 5
Exp: 1 year


Currently inactive on forums :(


« Reply #2 - Posted 2015-03-18 19:51:05 »

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.


"This code works flawlessly first time and exactly how I wanted it"
Said no programmer ever
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Olo

JGO Coder


Medals: 15
Projects: 3
Exp: 5 years


Metaphysical solipsism AFFIRMS your existence


« Reply #3 - Posted 2015-03-18 20:08:21 »

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.

-Can you fix it?
-No, I can't. But I can bypass it with one of these.
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1869 views)
2018-06-10 19:43:48

EgonOlsen (1901 views)
2018-06-10 19:43:44

EgonOlsen (1258 views)
2018-06-10 19:43:20

DesertCoockie (1703 views)
2018-05-13 18:23:11

nelsongames (1379 views)
2018-04-24 18:15:36

nelsongames (2003 views)
2018-04-24 18:14:32

ivj94 (2753 views)
2018-03-24 14:47:39

ivj94 (1955 views)
2018-03-24 14:46:31

ivj94 (3045 views)
2018-03-24 14:43:53

Solater (1090 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!