Вопрос

I have written a small graphical application in C in which I drew a box and a circle inside it (like a ball in the room). When circle touches one of the boundaries it bounces back.

I have used following sample code for that:

xVelocity = 5;
yVelocity = 5;

if(circle.x <= 0) {
    xVelocity = 5;
}

if(circle.y <= 0) {
    yVelocity = 5;
}

if(circle.x>=box.width) {
    xVelocity = -5;
}

if(circle.y>=box.breadth) {
    yVelocity = -5;
}

drawCircle();

I use refresh rate of 50ms to run through the loop to update position and draw the circle. However when I increase the speed of the circle, either by reducing refresh time or increasing velocities, flickering occurs. Also if I increase velocities, circle goes out of bounds before collision is detected. I used Turbo C to write this program.

I would like to know how to increase frame rate so that flickering does not occur. Is there any other solution to this problem?

Это было полезно?

Решение

One way to reduze flickering is to synchronize the output of the graphics to the monitor and only redraw it if it is in the vertical blank.

Another option is to use a backbuffer. You draw into a copy of the graphics display, and when you are done, put that on the screen.

Другие советы

Flickering is caused when the background is erased.

The solution is to draw on a different surface (a back buffer) and only when you're done copy it to the display/render buffer

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top