Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML.Net (C#) state based event handling.  (Read 6476 times)

0 Members and 1 Guest are viewing this topic.

Thondrod

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
SFML.Net (C#) state based event handling.
« on: June 27, 2012, 05:03:21 am »
Hi all! I hate to ask a question with my first post, but I'm in a bit of a bind.

I'm using SFML.Net to develop a game with C#, and I ran into a problem when attempting to convert some code over from the "Game from Scratch C++ and SFML Edition" tutorial (found here: http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition.aspx).

Basically, I'm trying to display a splash screen that can be dismissed by pressing any key or mouse button. The problem I have is that, from my understanding, I have to use DispatchEvents() to handle any events, and those events get sent to my event handlers which execute code I didn't necessarily want to execute in this given situation.

In the tutorial, GetEvent() is called to simply check for keyboard or mouse input and exit the loop like follows:
sf::Event event;
   while(true)
   {
     while(renderWindow.GetEvent(event))
     {
       if(event.Type == sf::Event::EventType::KeyPressed
         || event.Type == sf::Event::EventType::MouseButtonPressed
         || event.Type == sf::Event::EventType::Closed )
       {
         return;
       }
     }
   }

What I want to know is if it's possible to check for input within a loop without having to call my primary event handlers. Otherwise, the only solution I can think of is to create a switch case within my handlers that checks for the game state. If the game state is "ShowingSplash", the handlers would update my game state from "ShowingSplash" to "ShowingMenu" when a key or mouse button is pressed, and then I would break out of the splash screen loop by checking if the game state has changed. That seems much more complicated than necessary for simply getting out of a loop on a key or mouse button press.

Any help would be greatly appreciated!
Edit: Hope this is in the right spot. It seems weird to put an events question in the graphics area, but I figured that's where it belonged since RenderWindow is a member of Graphics.
« Last Edit: June 27, 2012, 05:05:11 am by Thondrod »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML.Net (C#) state based event handling.
« Reply #1 on: June 27, 2012, 08:06:45 am »
There's no other way of handling events with SFML.Net, you have to adapt the code.

Quote
Hope this is in the right spot. It seems weird to put an events question in the graphics area, but I figured that's where it belonged since RenderWindow is a member of Graphics.
Events are part of the Window module, and this way of handling them is specific to the .Net binding ;)
Laurent Gomila - SFML developer

Thondrod

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: SFML.Net (C#) state based event handling.
« Reply #2 on: June 27, 2012, 02:27:00 pm »
Alright, thanks. I suppose designating keypresses by game state is somewhat intuitive, even if it feels wrong to me to code it that right now. Thanks so much for the great support and effort here too.

 

anything