Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

An effective way to manage states?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 GrimV5   Members   


Posted 28 January 2014 - 05:18 PM

I'm making a 2d rpg game in c++ with sfml, and right now I am experimenting with game states.  Right now I am using a State* state[] that will store different states (for different areas) as they are found (unless they are menus in which they will already be there).  That way if I leave an area and then come back to it later (don't worry how I do this part, it works).


My question is this: is there a more efficient way of managing states for this type of game?  At some point a State* array will just become to big and inefficient.

#2 L. Spiro   Members   


Posted 28 January 2014 - 08:36 PM

What does it mean to “find” a state?  What is the relationship with menus?


Are you talking about uncovering part of a screen as you move over it?  Killing enemies on a certain screen?  What tasks you have accomplished on a certain screen?




L. Spiro

#3 Alundra   Members   


Posted 28 January 2014 - 08:41 PM

You are making one state by level if I understand correctly,I think it should be better to do a design to reuse a map and just switch of map.

You can use component to help on the logic of game surely and have object type who contains them and then save the object.

Then it's just a question of making the map and switch, like that it's the same as you switch of state but more efficient.

Edited by Alundra, 28 January 2014 - 08:41 PM.

#4 SeanMiddleditch   Members   


Posted 28 January 2014 - 11:25 PM

Echoing the last comment, I would typically expect to see states like Loading, MainMenu, Options, Pause, and Playing. The Playing state would then have a completely different layer to handle the active map/area. A pure state machine makes a lot of sense for simpler UI flows and a stack of states works best when you have lots of nested UI, like options menus or intricate inventory management or the like.

Separate levels rarely benefit from their own state. Levels are best described by data, not code. The way the game behaves does not change between levels 1 and 2. Good games usually have a consistent set of rules (code) and a progression of challenges using those rules (data). Even things like mini-games are integrated into the game rather than being separate modes/states increasingly often.

Game Developer, C++ Geek, Dragon Slayer - http://seanmiddleditch.com

C++ SG14 "Games & Low Latency" - Co-chair - public forums

Wargaming Seattle - Lead Server Engineer - We're hiring!

#5 Munchkin9   Members   


Posted 29 January 2014 - 01:51 PM

For the levels themselves one option would be to create a class Level. And make different instances of that class for each level. This class could then keep track of all the information you want. So in a circumstances that you were to leave and then return to an area the information would still have been saved.

As to how you organize keeping track of the different Level Instances that is up to you and the game you are making. If the areas represent sections of a map, a 2d array would allow you to access each Instance by its position on the grid. If the areas represent separate levels entirely than a simple array would do. If you know before hand how many areas there are then creating and naming each one on initializing the game might be preferable.

I guess we just need more information about your game to give you more advice. But yes I agree with the above, definitely keep menu states and levels separate. You will avoid a lot of headache if you do, trust me.

Hope this helped.

#6 NEXUSKill   Members   


Posted 31 January 2014 - 02:00 PM

Levels are not game states, levels are content of a game state, specifically, gameplay, Game states are used to sepparate contexts of your application that have radically different logics, a menu is very different than gameplay, and maybe you have other states, like a world map and a battle stage, the logic in each of them is very different to the others and there is a connection between them, look up state machines. Between different levels, the logic of the gameplay itself is likely to be more or less the same.


As for levels, if your game is linear you could have a simple array, if the array is too big it might be more clear and efficient to hold a link to the next level within the current level itself, maybe in the exit, so if you have multiple exits you can use a different link in each one. As for the transition from one level to the next, you just initialize the Gameplay state with a new level as content, maybe put in a loading screen if it takes a while.

Game making is godlike

LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.