Click to See Complete Forum and Search --> : Working with DC's
DarkMoose
Oct 12th, 2000, 07:41 PM
I am having trouble with storing graphics. I created a new DC and BitBlted my tileset on it. Now I need to copy the tiles from there and paste them right below the tileset to make the actual map of the current area. All of the code is working except the part that BitBlts the tiles from the set to the map. I wanna do this all on the same DC but it doesn't work... What am I doing wroooong ohh someone TELL MEEEE I'M GOING INSANE!!!!!!!! ...er..sorry. :)
kedaman
Oct 12th, 2000, 08:08 PM
YOu shouldn't have the map area and the tileset on the same DC, but if you just pasted your code here then we could understand what's not working?
DarkMoose
Oct 13th, 2000, 02:25 PM
Why can't I use the same DC for map and tiles? I thought the whole idea of VB is to save space... :| Anywayz, let's forget about what DC I save it on for now. I just need to know how to BitBlt something to a DC. The way i got the tileset there was with this:
MyDC = CreateCompatibleDC(Form1.hdc)
TilePic = SelectObject(MyDC, LoadPicture(AppPath & TileSet & ".gif"))
BitBlt MyDC, 0, 0, 493, 493, TilePic, 0, 0, vbSrcCopy
This works ok. The tileset goes into the DC and is stored there. Now, I need to copy individual tiles from there and BitBlt them elsewhere to build the map. I currently have the code inside 2 for loops and it is like this:
BitBlt MyDC, ReadTilesX * 46, ReadTilesY * 46 + 493, 46, 46, MyDC, TileArray(ReadTilesX, ReadTilesY).TileSrcX, TileArray(ReadTilesX, ReadTilesY).TileSrcY, vbSrcCopy
So all that does is copy a tile from the DC and BitBlts it elsewhere, on the same DC. Well, I WANT it to do that anyway... I think I'm missing something here...do I need to use that select object thing again? Or is it because i'm blting to the same DC!? Someone tell me what iz wrong!! :)
kedaman
Oct 13th, 2000, 02:45 PM
It may ofcourse be that you blt out of the contents of the bitmap, and that will automatically fall off without any errors. Now why don't you try to blit it to another DC that surely is empty and has the size you need to make a map? Use createcompatiblebitmap and you'll have another bitmap.
DarkMoose
Oct 13th, 2000, 03:23 PM
Ok It still doesn't work but I'm not really sure if I'm doing it right. I tried this:
MapBitmap = CreateCompatibleBitmap(Form1.hdc,MapWidth,MapHeight)
Then I just substituted MyDC with MapBitmap in that piece of code in my last reply. Please tell me i'm doing something wrong here.
kedaman
Oct 13th, 2000, 03:29 PM
did you use selectobject with thatone on the new DC?
DarkMoose
Oct 13th, 2000, 03:32 PM
Ahh, I thought it might be because of that. I'm not really sure how or when to use SelectObject. can you quickly explain it and how i can use it in my situatioN?
kedaman
Oct 13th, 2000, 03:42 PM
ahdc = CreateCompatibleDC(Form1.hdc)
SelectObject ahdc, MapBitmap
BitBlt hdc, 0, 0, MapWidth, MapHeight, ahdc, 0, 0, vbSrcCopy
Now you just use Selectobject the way you did before, attach the mapbitmap into your new dc, here called ahdc
DarkMoose
Oct 13th, 2000, 03:57 PM
KYAHAHAHAHAHAHA IT'S ALIIIIIVEEEE!!! Er... hi... ;D It works now, you rawk kedaman ;D
kedaman
Oct 13th, 2000, 04:21 PM
hehe ;) have fun!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.