bberak / react-native-game-engine

A lightweight Game Engine for React Native 🕹⚡🎮
MIT License
2.89k stars 174 forks source link

Addition touch events to GameEngine #41

Closed adimallikarjunareddy closed 4 years ago

adimallikarjunareddy commented 4 years ago

Is there a way to pass additional touch events to GameEngine? Or in other words can we configure GameEngine to receive inputs other than the default touch events?

If we are using game controllers with the device, we may need to handle these events instead of relying on touch events.

Currently systems components are invoked if there is any touch event and I would like to know if there is any way to send additional events along with it?

bberak commented 4 years ago

Hi @adimallikarjunareddy,

The GameEngine accepts a touchProcessor prop that you can use to provide your own touch processing logic. You can take a look at the DefaultTouchProcessor to see how the interface/api works.

Alternatively, you can write a custom system that will read input from your game controller and inject it into the args that get passed down to subsequent systems. I use this paradigm quite often.. Here is an example of my GamepadController system, here is how I add it to the systems array and here is how I would use it:

const SomeOtherSystem = (entities, { touches, gamepadController }) => {
   if (gamepadController.a)
      console.log("Button 'a' was pressed");

   return entities;
};

Let me know if that helps @adimallikarjunareddy :)