Jump to content

  • Log In with Google      Sign In   
  • Create Account

Help with event system in SFML 1.6


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
1 reply to this topic

#1 stitchs   Crossbones+   -  Reputation: 1310

Like
0Likes
Like

Posted 18 November 2012 - 01:06 PM

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:
  • 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.

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.

Sponsor:

#2 superman3275   Crossbones+   -  Reputation: 2061

Like
0Likes
Like

Posted 18 November 2012 - 10:04 PM

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:

// 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.

Edited by superman3275, 18 November 2012 - 10:06 PM.

I'm a game programmer and computer science ninja ph34r.png!

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

 

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here smile.png!





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.



PARTNERS