bberak / react-game-engine

A lightweight Game Engine for the web (React) 🕹⚡🎮
MIT License
420 stars 25 forks source link

unable to access event types within systems #13

Closed ravenwilde closed 1 year ago

ravenwilde commented 4 years ago
const GameStart = (entities, { time, events }) => {
  if (events.length) {
    console.log("GameStart - events", events);
  }
  return entities;
};

I'm consistently logging an empty [] array after an event fires - is there any way to access an events' type from within a system function?

bberak commented 4 years ago

Hi @ravenwilde,

Can you describe your use case in more detail?

The events array will be contain event information for 1 frame after the dispatch method is called on the GameEngine component. When the frame completes the array is cleared.

This allows components outside of the GameEngine to communicate with it and vice versa. So yes, you should be able to read events info from the systems.

How are you sending events to the GameEngine component?

Something like this should work:

//-- Assuming you have a ref to the GameEngine component
this.refs.gameEngine.dispatch({ name: "some-event-name" });
ravenwilde commented 4 years ago

Hi @bberak , thank you for taking the time to respond. I ended up locating your demo app on npm and was able to figure out how to wire everything up. Nice work on this game engine! I'm shocked at how easy this has been to pick up and build with https://codesandbox.io/s/cold-resonance-5ywvz?file=/src/App.js

bberak commented 4 years ago

Thanks for the kind words @ravenwilde - let me know how it goes (always interested to see what people come up with)!