SFML community forums

Bindings - other languages => DotNet => Topic started by: WaterNode on January 27, 2013, 09:22:58 pm

Title: SFML Events w/C#.NET
Post by: WaterNode on January 27, 2013, 09:22:58 pm
I'm trying to figure out how to register events in SFML.NET, and I'm clueless. I'm looking for tutorials, but a no go.

This is my code so far:
using System;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace Example
{
    class Program
    {
        static void OnClose(object sender, EventArgs e)
        {
            // Close the window when OnClose event is received
            RenderWindow window = (RenderWindow)sender;
            window.Close();
        }

        static void Main(string[] args)
        {
            // Create the main window
            System.Threading.Thread.Sleep(1000/50);
            RenderWindow window = new RenderWindow(new VideoMode(1024, 768), "Game");
            window.Closed += new EventHandler(OnClose);
            // Load a sprite to display
            Texture texture = new Texture("Graphics/mainCharStand.PNG");
            Sprite sprite = new Sprite(texture);
            // Start the game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();
               
                // Clear screen
                window.Clear();

                // Draw the sprite
                window.Draw(sprite);

                // Update the window
                window.Display();
            }

        }
    }
}
 

Is this how you register events? Or am I mistaken.
window.Closed += new EventHandler(OnClose);
Title: Re: SFML Events w/C#.NET
Post by: Hiura on January 27, 2013, 10:02:38 pm
I never used SFML.Net but it looks the same as this example (https://github.com/SFML/SFML.Net/blob/master/examples/window/Window.cs#L20) so I would say it's correct.

Isn't it working ? What's your issue ?
Title: Re: SFML Events w/C#.NET
Post by: SymegPL on January 27, 2013, 10:05:47 pm
Yes. When window is closed then OnClose method was triggered.
Title: Re: SFML Events w/C#.NET
Post by: WaterNode on January 27, 2013, 10:17:36 pm
Thank you for clarifying.
Title: Re: SFML Events w/C#.NET
Post by: krzat on January 27, 2013, 10:45:25 pm
You can also write:
window.Closed += OnClose;
or
window.Closed += (s,a) => window.Close();
Title: Re: SFML Events w/C#.NET
Post by: PlankSkills on March 27, 2020, 01:41:04 pm
There is something wrong with your code:
 "window.isOpen()"
window.isOpen isn't a method, you should use it like this:
 "window.isOpen" // No Parenthesis