Clearing the Screen

Started by
7 comments, last by acematti 20 years, 3 months ago
Hi Im trying to make a basic pong game howevr I have got stuck on how to clear the screen so the ball doesn''t leave a trail behind it. I know in other languages its just CLS but this wont work for a window. Any ideas? Matt
Advertisement
What programming language are you using? Are you using text mode or a graphics library? If a graphics library which one?
Whoah sorry I cant believe I din''t post that,

Im using C++ I created my own window class and bitmap library.

Its not text mode, not too sure what you mean by the graphics library.

Its rather annoying because I know what I want to do its just I cant seem to find the code examples to do it.

Thanks in advance.


Matt
Ok, I''ll assume you''re using basic Windows GDI graphics then. IIRC you can call SaveDC() on your graphics context before drawing and then later call RestoreDC() to restore things to it''s original state. This will let you effectively clear the surface. If that doesn''t work, probably the best option is to use FillRect() with a brush that has the background color to wipe the surface.

If you''re using double buffering, the SaveDC()/RestoreDC() trick probably isn''t too useful, and you should just FillRect() the offscreen surface.
Hmm that seems to have done the trick however It flickers like mad, think i may have to do more research into this than I thought.

ANy ideas on how to reduce the flickering?

Will it be the timing in the game that I have set up?

The whole game gets painted by invlidating the rect which in turns calls the GamePaint() function that draws the ball.

Sorry to be such an idiot just trying to learn how to do things in windows rather than in something like Blitz Basic.

Looks like I will be back to the books I think


Matt
One trick to reduce flickering is to use double buffering: do all your drawing on an offscreen surface and then blit that offscreen surface to the screen when you''re done. One way to get an offscreen surface is to use CreateCompatibleDC() and CreateCompatibleBitmap() together.
Uselly when I try to clear my screen, I use a rect the hole size of my screen and I make it print before or after everything was printed. But beware if your using gdi you will obligated to use double buffering or you will always see some crappy things. Good Luck for your pong game !

Kevin
Kevin
Right so to double buff I would draw all of my stuff onto another surface, would this be another RECT?

Thanks for throwing me some light on this matter.

Now I know what to look for should make things easier.


Cheers


Matt
quote:Original post by acematti
Right so to double buff I would draw all of my stuff onto another surface, would this be another RECT?
...


No, a rect is just a struct containing 4 longs you need to create a temporary windows device then draw your stuff in there. When you are done doing that you blit it to your main window device, and then repeat the process. Well my explanation might not have been very clear so take a look at this link:

http://www.winprog.org/tutorial/animation.html




This topic is closed to new replies.

Advertisement