Sign in to follow this  

2008 VC++ How can I Draw using Layers

This topic is 3491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, it's my first post - so let me know if I'm out of line with the program :) I am a beginner who learned some Visual C++ 2008 and made a simple 2D game: http://www.yboris.com/gravitywars/gravitywars.html The code is a combination of stuff I found online and my 'ingenuity'. Sadly I am unable to find or figure out how to create different layers. I want something very simple: 3 Layers (1) stars (2) lines (3) planets This way I can simply have a function that draws lines - but always 'below' the planets - so that I don't need to worry about drawing over the planet by accident. I'm sure it's something rather simple - but I can't figure it out :( Another VERY big problem - every time I minimize the program or a window is on top of the game - EVERYTHING BENEATH is erased :( ... I'd like to have some sort of a way of 'saving' what is drawn (like when you paint in MS Paint) from simple intrusions like that :)

Share this post


Link to post
Share on other sites
There is no built-in support for layers in any 2D graphics library I know of (neither GDI, nor Allegro or SDL).

What people usually do is keep several lists (eg. a background, a statics and an entities list). Instead of drawing the bitmaps/sprites right away, the game will then first add them to one of those lists and when everything has been added, the lists will be drawn in the desired order (eg. first draw everything queued in the background list, then everything in the statics list and then everything in the entities list).

If your window's contents are erased after the window has been invalidated, you're doing something wrong. Windows expects you to redraw the whole window after each WM_PAINT call (GDI clipping will sort out the regions that need not be drawn).

You can create a double-buffered window and keep your own backbuffer bitmap that you'll just blit to the screen when a WM_PAINT message arrives. That would guarantee that the backbuffer contents aren't lost when your window is invalidated.

Share this post


Link to post
Share on other sites

This topic is 3491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this