2
\$\begingroup\$

I'm working at my first game and I've decided to build a simple component based engine. I found really useful to work in that way but I still miss some fundamentals probably.

Let say that I have a super simple game like this: A spaceship that moves where user touches/clicks the screen. Before moving the ship the user has to select it by a touch/click over the spaceship sprite and to deselect it the user has to touch/click wherever outside the sprite.

To build something like that I'd use this structure:

Spaceship Entity
     |_____________ Movable Component  (contains coordinates)
     |_____________ Drawable Component (contains a sprite)

Rendering system:
     - Check for every entities with drawable and movable component and draw 
       the sprite at the coordinate defined by movable component

Or something similar..

At this point I would like to add an input manager. But err... I really don't know which is the best way to attach an Input Manager in this structure! Do you think it's a good idea to create something like a Selectable component and then create a Input System? The problem is that probably it would be useful to keep track of the selected object in other systems too and I suppose that this part could be managed outside the Component system.

So my question is how to deal with a behaviour that is so important and generic like user interaction in a Component based architecture. Have you had experience with this problem? Which solutions did you choose?


Edit: And in general I suppose that is a valid idea to keep track of the current selected object. Using a component based architecture how can I manage shared information?

\$\endgroup\$
  • 2
    \$\begingroup\$ I think that's been answered here. The third part of the question asks about input and there are a few answers for it. Essentially, you use a system and component, just like everything else. The system receives the input and applies it to the entities that have the control component. \$\endgroup\$ – MichaelHouse Apr 25 '13 at 16:29
  • \$\begingroup\$ @Byte56 I suppose that is a valid idea to keep track of the current selected object. Using A component Based architecture how can I manage shared information? (I edit the question adding this sentence) \$\endgroup\$ – MatterGoal Apr 25 '13 at 16:33
  • \$\begingroup\$ You add the control component to the entities you want to control. You remove it from the entities you don't want to control. This allows you to control multiple entities if you want. And acts as an entity selector. \$\endgroup\$ – MichaelHouse Apr 25 '13 at 16:36