namespace Example { class Program { staticvoid OnClose(object sender, EventArgs e) { // Close the window when OnClose event is received RenderWindow window =(RenderWindow)sender; window.Close(); }
staticvoid 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.
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