SFML community forums

Bindings - other languages => DotNet => Topic started by: Anteara on July 29, 2013, 06:52:59 pm

Title: Using events, confusion
Post by: Anteara 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));
    }
}
Title: Re: Using events, confusion
Post by: Laurent on July 29, 2013, 06:56:58 pm
http://en.sfml-dev.org/forums/index.php?topic=12407.msg86529#msg86529
Title: Re: Using events, confusion
Post by: Anteara 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#?
Title: Re: Using events, confusion
Post by: Laurent on July 29, 2013, 08:13:08 pm
Yes.