2008 VC++ How can I Draw using Layers

Started by
0 comments, last by Cygon 15 years, 11 months ago
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 :)
http://gravitywars.yboris.com
Advertisement
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.
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.

This topic is closed to new replies.

Advertisement