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

Author Topic: Using events, confusion  (Read 4610 times)

0 Members and 1 Guest are viewing this topic.

Anteara

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Using events, confusion
« on: July 29, 2013, 06:52:59 pm »
Hi all, I've made my program functional without the need to use Event. However, as I've noticed the c# version of SFML doesn't have pollEvent. It does however have DispatchEvent, but it takes no arguments, so I'm unsure as to know it will know which event variable to check.

I'm trying to get my level editor to show more on resize - instead of stretching it. The tutorial at
http://www.sfml-dev.org/tutorials/2.0/graphics-view.php poses a solution, however I'm not totally sure how I can get this to work in c# (no pollEvents, and when I check my event.Type - it always returns 'Closed'.)

Could you please point me in the right direction?

This is the code I'm referring to:

// the event loop
sf::Event event;
while (window.pollEvent(event))
{
    ...

    // catch the resize events
    if (event.type == sf::Event::Resized)
    {
        // update the view to the new size of the window
        sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
        window.setView(sf::View(visibleArea));
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

Anteara

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Using events, confusion
« Reply #2 on: July 29, 2013, 07:27:44 pm »
Okay, so i looked at the wiki, tutorials and documentation.

The only thing i can think of is that I have to define the event handler myself? I can't just do if event = whatever... I just make a function to perform if that event is ever fired?

            rw = new RenderWindow(new VideoMode(800, 600), "Game");
            rw.Closed += (s, a) => rw.Close();
            rw.MouseMoved += rw_MouseMoved;
            rw.Resized += rw_Resized;

This is from the example.

        void rw_Resized(object sender, SizeEventArgs e)
        {
            var view = rw.GetView();
            view.Size = new Vector2f(e.Width, e.Height);
            rw.SetView(view);
        }

So this part would basically be the same as the tutorial but in c#?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Using events, confusion
« Reply #3 on: July 29, 2013, 08:13:08 pm »
Yes.
Laurent Gomila - SFML developer