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.


Topics - Dr_Asik

Pages: [1]
1
Graphics / Sprites rendered approximately
« on: November 05, 2009, 02:50:11 am »
I am coding a remake of Space Invaders, and my artwork is consequently very low-res. I need it to be drawn with pixel perfect accuracy.

I am using the Sprite class to draw my artwork to the screen, unfortunately, they appear blurry, even if I don't scale/rotate them. Is this a known issue with SFML?

2
General / Basic game loop question
« on: November 04, 2009, 06:15:04 am »
Hello, I am coding my first non-XNA game and using SFML in C++. XNA took care of the game loop but now I have to code my own.

I have come up with this:

Code: [Select]
   Clock clock;
    float timeBetweenFrames = 1000.0f / (float)updatesPerSecond_;

    while (app_.GetEvent(event)) {
        if (event.Type == Event::Closed) {
            app_.Close();
        }
    }

    while (app_.IsOpened()) {
        clock.Reset();
        Event event;

        update(timeBetweenFrames);
        draw(timeBetweenFrames);

        while (clock.GetElapsedTime() < timeBetweenFrames) {
            sf::Sleep(0.0005f);
        }
    }
(Where app_ is a RenderWindow and updatesPerSecond_ is an int, here 60.)

The problem here is that the window becomes non-responsive. I don't really get it as events will still get processed [updatesPerSecond_] times per second (in my case 60). Do I really need to be constantly polling for events? In that case, wouldn't a dedicated thread be more appropriate?

In any case, I "fixed" the problem by removing the call to sleep and replacing it with constant polling of events.

Code: [Select]
   Clock clock;
    float timeBetweenFrames = 1000.0f / (float)updatesPerSecond_;


    while (app_.IsOpened()) {
        clock.Reset();
        Event event;

        update(timeBetweenFrames);
        draw(timeBetweenFrames);

        while (clock.GetElapsedTime() < timeBetweenFrames) {
            while (app_.GetEvent(event)) {
                if (event.Type == Event::Closed) {
                    app_.Close();
                }
            }
        }
    }


This is responsive, and draw and update should be called [updatesPerSecond_] times per second.

Still, I'm a bit lost. What if some part of my game needs to be updated as often as possible? For instance, the audio engine, or even just the graphics. Anytime I'm doing some game processing, I am not polling events, so will the window become non-responsive again?

Pages: [1]