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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Wuzseen

Pages: [1]
1
DotNet / Blinking Shapes, Blinking Sprites, etc.
« on: May 09, 2012, 10:10:42 pm »
I'm pretty new to SFML, and I like the ease of the .NET implementation.  I'm using 2.0 right now and I'm running into a few issues, that I hope are pretty basic.

As I'm exploring and getting into the groove of things I just want to make an event that when I click, it draws a rectangle at a fixed point (eventually I'll want to do it where I clicked... one thing at a time).

I've been able to have it sort of work, however the below code causes the white rectangle I make to flicker until I click a couple times.  I'm not entirely sure why this is the case and could really use some input.

 class Program
    {
        static void OnClose(object sender, EventArgs e)
        {
            Console.WriteLine("Closing");
            RenderWindow window = (RenderWindow)sender;
            window.Close();
        }

        static void OnClick(object sender, MouseButtonEventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;
            if (e.Button == Mouse.Button.Left)
            {
                Console.WriteLine("LMB Clicked");
                window.Clear();
                Vector2f recSize = new Vector2f(50, 80);
                RectangleShape rect = new RectangleShape(recSize);
                window.Draw(rect);
            }
        }

        static void Main(string[] args)
        {
            RenderWindow app = new RenderWindow(new VideoMode(800, 600), "SFML Window");
            app.Closed += new EventHandler(OnClose);
            app.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(OnClick);

            while (app.IsOpen())
            {
                app.DispatchEvents();
                app.Display();
            }
        }
    }

Pages: [1]
anything