Jump to content
  • Advertisement

Archived

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

Megatron

A simple DirectDraw example

This topic is 6327 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

I''m looking for a simple example of loading a bitmap "background" and putting another .bmp on top of it to move around with the keyboard. I have no problem blitting the background .bmp, but moving a sprite around is gumming things up. Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Just make some variables that hold the sprites x,y positions, then increase/decrease those when the person hits the arrow keys. And make sure you re-blt the background every frame, otherwise you''ll have a million little sprites all over the screen. If you still can''t figure it out, say something and I''ll try to post some code for you. Good Luck.



"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka

Share this post


Link to post
Share on other sites
I guess I wasn''t clear...movement itself isn''t the problem. The problem is putting the character sprite on the screen (one .bmp on top of another). I could move it around easy enough after that. Thanks.

Share this post


Link to post
Share on other sites
My bad. I don''t really understand what the problem is. All you have to do is blt the background the the back buffer, then blt the sprite on to the back buffer, then flip the back and front buffer. Are you having trouble making it transparent?



"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka

Share this post


Link to post
Share on other sites
I guess my problem is this:

I''ve been reading "Tricks of the..." and I''ve been re-writing all the code in the book and switching it around so I understand it etc. Anyway, I got through the example where I load a 24-bit .bmp to the screen with DirectDraw, and that makes sense. The next example, however, has 3 animated aliens which are drawn from a tile-map surface moving across the screen with timing and whatnot. It is a wee bit big a step from loading a .bmp file, so I want to break it down a bit.

Here is the code that is giving me trouble -> http://missoula.bigsky.net/law/bltsource.txt

I want to disect it so that it loads a bitmap background and a sprite to the back buffer, and then flips the back buffer to the primary buffer. Then I''ll deal with moving the sprite around the screen.

Bleh.

Share this post


Link to post
Share on other sites
BitBlt has the right idea. The easiest way to accomplish what you are trying to do is the following:

1. Load up both image files onto surfaces.
2. Draw your background image to the back buffer using Blt or whatever wrapper function you have.
3. After the background is drawn, draw your sprite.
4. Flip

That''s all there is to it. By drawing the sprite second, it is drawn on top of the background image. This should get you to the point you are looking for. If it is drawing the sprite that has got you confused, it is the same as drawing the background. If the sprite is only a small section of a larger bitmap, then you need to create a RECT structure with the location of your sprite on the image and pass the RECT to Blt. Hope this helps.

-----------------------------
kevin@mayday-anime.com
http://dainteractive.mayday-anime.com

Share this post


Link to post
Share on other sites
Okay, so I''ve done that. I think my GameMain() function is money, but my GameInit() function is messed up. I can''t quite figure out what order to put these things in, and I also am having problems getting it in 32-bit color mode. Any suggestions?

Here are those two functions http://missoula.bigsky.net/law/DDRAW.txt

Share this post


Link to post
Share on other sites
32 Bit color mode is rather iffy on most cards. You may want to try going into 24 bit or even better, 16 bit. You may have more luck. As for your order, you need to make sure that you create your sprite on a OFFSCREEN PLAIN surface AFTER you have initialized DirectDraw and created your primary and secondary surfaces. From the looks of your code, you seem to be doing that.

Your Game Main seem fine, but I don't quite see what the problem is. Is your sprite not displaying correctly? Is your sprite displaying at all? Another thing I noticed, you are trying to start up in 32 Bit mode, yet you are creating and filling out a 256 color pallette (8 bit). Is this really what you are trying to do?

-----------------------------
kevin@mayday-anime.com
http://dainteractive.mayday-anime.com

Edited by - grasshopa55 on July 24, 2001 8:56:01 AM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!