Jump to content
  • Advertisement
Sign in to follow this  
bobrules

How to handle game state changes in event system with decoupled systems

This topic is 2636 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I've been reading a lot of Game Coding Complete and I'm using a similar approach the author's of separating rendering and logic as well as his event system.

What I was wondering though, was say I have a GameLogic class that handles the logic and a GameView class that handles the rendering, how would I go about connecting the two on game state changes?

Let's say game states are ints.

Say GameLogic's current state is the MainMenuState. I change GameLogic's state to the MainGameplayState and fire a StateChangedEvent with the id of the new state. The GameView receives this event and checks what state is the new state. If it's the MainGameplayState it plays a little sound or plays a little screen animation or does something specific to this state that the logic wouldn't care about.

Is there a better way to do this?

Share this post


Link to post
Share on other sites
Advertisement
So, you want a little jingle and/or animation when a state change occurs?

This may not directly help, but just as a different approach: I have a GameState class, and each GameState owns it's own GameLogic class. This keeps me from having a logic object that becomes too large and unwieldy. Right now I just keep a pointer to the active state, but I could also implement a state stack.

As far as playing some jingle or animation on a state change, if it's the same for all state changes, I might just have the sound or render class respond to the event. Otherwise, my first thought would be to add an OnActivation() method to the GameState class, and do it here.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!