Sign in to follow this  
stitchs_login

Help with event system in SFML 1.6

Recommended Posts

stitchs_login    1361
Hello,

I have a quick question regarding SFML 1.6 for C++. I have searched around for information but am limited to the tutorials on the SFML website.
I am currently in the process of making a separate Main Menu class and am wondering 2 things:
[list=1]
[*]Do I need to create a separate events queue for the menu, and destroy it when I move into the Main game (making a new one for each 'state'?). Or, do I pass in the events queue from the Main window by reference, and feed events back into it, thereby using the same events queue for the Menu and Game (and as well as other game 'states').
[*]Where do I handle events relating to the Menu, do I handle the, within the loop that checks and processes events or, do I handle them like in the tutorial linked here: http://www.sfml-dev.org/tutorials/1.6/sources/window-time.cpp , after where elapsed time is set.
[/list]

If you need anymore information, or a link to some of my code to help narrow down what I am getting at, I am more than happy to provide it.

Regards,

Stitchs.

Share this post


Link to post
Share on other sites
superman3275    2061
If you pass in a pointer to the event / window in question (Made a custom SFML event manager a few weeks back, so I'm a little rusty about which one to use) to a function, you can have that function check for whatever event you need. Also, I generally have an enum for the different states of my game (InMainMenu, InCredits, Playing, InGameOver, Exiting, etc.) and in the main loop, depending on which state I'm in, I'll do logic for (And render) different things.

Also, most events are handled by the window. (Mouse Events are Handled By The Window, generally). Since you only want one window per application, I would use the above method.

Example:

[CODE]
// My Gamestate Enum
enum GameStates
{
InMainMenu,
InCredits,
Playing,
InGameOver,
Exiting
};
//In My Main Application
if (CurrentGameState == InMainMenu)
{
//Logic
//Render
}
else if (CurrentGameState == InCredits)
{
//Logic
//Render
}
//ETC.
//ETC.
[/CODE] Edited by superman3275

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this