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

Author Topic: Blinking Shapes, Blinking Sprites, etc.  (Read 2744 times)

0 Members and 1 Guest are viewing this topic.

Wuzseen

  • Newbie
  • *
  • Posts: 1
    • View Profile
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();
            }
        }
    }
« Last Edit: May 10, 2012, 08:18:13 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Blinking Shapes, Blinking Sprites, etc.
« Reply #1 on: May 10, 2012, 08:19:32 am »
You can't do that.

You must have a main loop that clears/draws/displays, ie. that completely refreshes the window at every iteration.
Laurent Gomila - SFML developer