Archived

This topic is now archived and is closed to further replies.

acematti

Clearing the Screen

Recommended Posts

acematti    122
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

Share this post


Link to post
Share on other sites
SiCrane    11839
What programming language are you using? Are you using text mode or a graphics library? If a graphics library which one?

Share this post


Link to post
Share on other sites
acematti    122
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

Share this post


Link to post
Share on other sites
SiCrane    11839
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.

Share this post


Link to post
Share on other sites
acematti    122
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

Share this post


Link to post
Share on other sites
SiCrane    11839
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.

Share this post


Link to post
Share on other sites
cpp boy    116
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

Share this post


Link to post
Share on other sites
acematti    122
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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




Share this post


Link to post
Share on other sites