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

Author Topic: SFML Events w/C#.NET  (Read 6114 times)

0 Members and 1 Guest are viewing this topic.

WaterNode

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML Events w/C#.NET
« 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);

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: SFML Events w/C#.NET
« Reply #1 on: January 27, 2013, 10:02:38 pm »
I never used SFML.Net but it looks the same as this example so I would say it's correct.

Isn't it working ? What's your issue ?
SFML / OS X developer

SymegPL

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: SFML Events w/C#.NET
« Reply #2 on: January 27, 2013, 10:05:47 pm »
Yes. When window is closed then OnClose method was triggered.

WaterNode

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SFML Events w/C#.NET
« Reply #3 on: January 27, 2013, 10:17:36 pm »
Thank you for clarifying.

krzat

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: SFML Events w/C#.NET
« Reply #4 on: January 27, 2013, 10:45:25 pm »
You can also write:
window.Closed += OnClose;
or
window.Closed += (s,a) => window.Close();
SFML.Utils - useful extensions for SFML.Net

PlankSkills

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML Events w/C#.NET
« Reply #5 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

 

anything