 |

11-22-2003, 07:04 PM
|
|
Freshman
|
|
Join Date: Nov 2003
Posts: 44
|
|
Trouble with BitBlt..
|
|
Sorry guys, I'm new to VB, so I dont know a whole lot. I was reading some tutorials, but they weren't very detailed. You see, in my game, I have a frmLevel1 with a backcolor of black, a picRocket with a picture of a rocket in it (and the rocket picture has a black on the edges), and numerous lines, which are colored green. When I move the picRocket on the form, there is no problem, as both the form and the edges of the picture are black. The problem arises when i move the picRocket into a green line. Now, I do have a collision detector to prevent the rocket from going past the line, but when it collides with the line, you can see the corner of the picture overlapping the line, and I don;t want this. I tried utilizing BitBlt, but it doesn't seem to work (btw I modeled my BitBlt code after Lucky's VB Game Site's, if that helps). Here is my project, I hope someone out there can help:
|
|

11-23-2003, 02:17 AM
|
 |
Contributor
|
|
Join Date: Sep 2003
Location: Portland OR
Posts: 581
|
|
I donwloaded your game...
Quote: Originally Posted by dragmire03 ...I tried utilizing BitBlt, but it doesn't seem to work (btw I modeled my BitBlt code after Lucky's VB Game Site's, if that helps). Here is my project, I hope someone out there can help:
Unfortunately Bitblt-ing doesn't work too well on images that are anti-aliased. You want the edges of the sprite to be clean (preferably against a solid color background to make creating the mask easier)
There was a .jpg mask file included ("rocketmask1.jpg") with the zip, but it doesn't seem to be utilized by the Private Sub RenderRocket(), so that's another reason Bitblt isn't working properly.
Also I notice you are switching sprite images to include images with the rockets firing. Each sprite image (because they are different) will have to have its own sprite mask.
I don't have time to "fix" your game, but I'll try to clean up your sprites, generate the necessary masks and roll it into a sample demo with the correct Biblt calls...will post again later...
|
|

11-23-2003, 04:17 AM
|
 |
Contributor
|
|
Join Date: Sep 2003
Location: Portland OR
Posts: 581
|
|
I'm just too nice...
|
|
Attached is the cleaned up sprites, masks, and demo program to show how to bitblt them correctly.
Also enclosed are "Master" sprites with magenta backgrounds that I used with my AutoSpriteMaskCreator2 program to make the masks. It's a great program and takes a lot of the tedium out of creating sprite masks manually.
Here's the thread if you want to download it:
http://www.xtremevbtalk.com/t113541.html
|
|

11-23-2003, 07:35 AM
|
|
Freshman
|
|
Join Date: Nov 2003
Posts: 44
|
|
Wow! Thanks a lot, man! You've done wonders! I only have a few questions. In this block of code:
Code:
'Blit Rocket 1 to picbox with checkered background
BitBlt picResult1.hDC, 20, 10, 31, 90, picMask1.hDC, 0, 0, vbMergePaint
BitBlt picResult1.hDC, 20, 10, 31, 90, pic1.hDC, 0, 0, vbSrcAnd
I'm pretty sure the "20, 10" is for where you want to place the upperleft corner of pic1, but is that 20, 10 from the form's origin, or is it 20, 10 from the picResult's origin? And is the 20, 10 in twips or pixels, because i measured out 20 twips to the right and 10 twips down from the origin of picResult1, and that would pretty much put you in the upperleft corner of picResult1. But the place you BitBlt'ed it was further towards the center, and 20, 10 in pixels would make more sense. If this is the case, how would I determine where to put the rocket in relation to twips (my whole game is pretty much established on twips).
|
|

11-23-2003, 10:14 AM
|
|
Freshman
|
|
Join Date: Nov 2003
Posts: 44
|
|
ACk! I have a problem! I tried to do the BitBlt, exactly how your program did it, but not only will it not work, when i move the rocket, it leaves a trail of white behind it! Here it is, for anyone who cares:
|
|

11-23-2003, 09:54 PM
|
 |
Contributor
|
|
Join Date: Sep 2003
Location: Portland OR
Posts: 581
|
|
Bitblt is always uses pixels not twips...
Quote: Originally Posted by dragmire03 Wow! Thanks a lot, man! You've done wonders! I only have a few questions. In this block of code:
Code:
'Blit Rocket 1 to picbox with checkered background
BitBlt picResult1.hDC, 20, 10, 31, 90, picMask1.hDC, 0, 0, vbMergePaint
BitBlt picResult1.hDC, 20, 10, 31, 90, pic1.hDC, 0, 0, vbSrcAnd
I'm pretty sure the "20, 10" is for where you want to place the upperleft corner of pic1, but is that 20, 10 from the form's origin, or is it 20, 10 from the picResult's origin? And is the 20, 10 in twips or pixels, because i measured out 20 twips to the right and 10 twips down from the origin of picResult1, and that would pretty much put you in the upperleft corner of picResult1. But the place you BitBlt'ed it was further towards the center, and 20, 10 in pixels would make more sense. If this is the case, how would I determine where to put the rocket in relation to twips (my whole game is pretty much established on twips).
You're assumption is correct. The 20, 10 is the number of X and Y pixels from pic Results origin (0,0 in upper left corner). However those Bitblts that use Me.hdc are number of pixels from the form's origin.
A bit of trivia - Bitblt is the grandfather of almost all window's graphics copying API's (along with StretchBlt and PatBlt). I used them way back in 1989 with Windows 2.11 and Microsoft C 5.0 (ancient history --long before Visual Basic for Windows even existed). In the dawn of the Windows GUI age, there was no such thing as "twips", only pixels.
There are usually 15 twips per pixel, but you should use:
Code:
Pixels = Twips \ Screen.TwipsPerPixelX
Twips = Pixels * Screen.TwipsPerPixelX
(this is the "official" way to let VB do the conversion)
I sorta anticipated you were going to have trouble "fixing" your game, (even with the right Bitblt code and correct sprites/masks). I will try to look at you attachment in your last post -- no guarantees though, I have several other VB projects I am working on and my time is limited...
|
|

11-24-2003, 02:23 AM
|
 |
Contributor
|
|
Join Date: Sep 2003
Location: Portland OR
Posts: 581
|
|
This is as much as I am going to do...
Okay, I've got the bitblt working and eliminated the "smear", but you probably won't like the result (it flickers badly).
There are a number of bad design decisions contained in your game.
First and foremost is the use of multiple timers that call each other (interlocking). This makes it almost impossible to set a breakpoint anywhere in your program and step thru it using F8.
Major problem with Bitblt not working --you forgot to set the AutoRedraw for the rocket mask picture boxes to "True" - Yes this makes a BIG difference.
The smear is a bigger problem. It's caused by retained (persistant) Bitblt-ed rocket sprite images as the rocket sprite is animated (moves to different position). With a picturebox you could set Autoredraw to True and refresh it without flicker, but with a form using a bunch of lightweight controls (that have no hDC --like labels, lines) setting AutoRedraw to True only causes smearing and refreshing to solve the smearing problem causes the lightweight controls to flicker. (You can try setting the AutoRedraw of frmLevel1.frm to True in the attached project below to see this smearing effect).
So the bitblting (with transparent background) is working...leave the picRocket non-visible and it still works to orient the sprite positioning and for collision control.
To solve the flickering problem what I recommend is put a picbox on the form...call it say picBuffer...and bitblt to picBuffer the part of frmLevel1.hdc where you are going to RenderRocket (bitblt) the rocket sprite TO -- BEFORE you actually bitblt the rocket sprite. In essense you are taking a small snapshot of the background of the form UNDERNEATH where the rocket sprite is going.
Then, when the rocket sprite needs to be RenderRocket-ed (bitblt-ed) to a new position, copy the small snapshot of the background (underneath the rocket sprite that you saved to picBuffer) back to the same position on frmLevel1.frm. By doing so you obliterate the first bitblt of the rocket sprite (restoring frmLevel1.frm to look like its original state before ANY rocket sprite was bitblt-ed) and get the background ready to receive the second rocket sprite bitblting in it's new (slightly offset) position--with no smearing.
That's the theory of what remains to be done anyway...I don't have the time to code the whole thing for you...sorri
Also a couple of small things:
The line "picRocket.Picture = picRocket1.Picture" is not needed because picRocket should never be visible (all rocket sprites should be created thru bitblt-ing).
Calling RenderRocket during the FormLoad is useless because it's only after FormLoad is completed (over) that a Form actually exists to Bitblt to. That's why I have placed the RenderRocket in the Do While True loop in Form Activate. The Form Activate comes after the Form is loaded (and runs all the time the form is shown and has focus). Unfortunately, this code (in interacting with your multiple timers) maybe part of the flickering issue.
I added a Case Else to RenderRocket because when the program first starts (before any keys are pressed as part of the Timer3 GetAsyncKeyState monitoring) the Case Select doesn't select any of the other Rocket Sprite Bltblt statements. That's why, with picRocket non-visible, you wouldn't see a rocket (when the form first is shown) unless this special case is accounted for.
I would also put all the labels into their own picturebox or frame, This will reduce the flicker noticeability.
I would also use a BIG picturebox on the form and resize it to take up the whole background of the form. Then put your lines you have on the frmLevel1.frm into this picturebox.
Pictureboxes are easier to work with then form hdc's - you might even be able to use PaintPicture instead of Bitblt which is a little easier.
The other advantage is once you are working exclusively inside a picturebox the ScaleMode of the picturebox can be set to 3 - Pixels and you no longer have to deal with twips!!!
Good Luck
|
Last edited by rpgnewbie; 11-24-2003 at 02:29 AM.
|

11-24-2003, 12:38 PM
|
 |
Sinecure Expert
Preferred language: Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 6,725
|
|
Changing the Scalemode is not exclusive to the Picturebox. You can set
the Form's Scalemode to pixels to avoid twipsPerPixel conversions.
Also, you shouldn't post the same question in more than one forum,
since different people may answer the same question, doing duplicating
work unnecessarily.
My response to the same question in your other thread (which
rpgnewbie has now far exceeded here), was:
To use bitblt, you are not going to be bliting in picRocket and moving
picRocket. You will be bliting directly to your form. Since you have a
number of different images for your rocket, you will need to create
masks to go with each image. If you're using an NT (XP) based machine
you may be able to use Transparentblt, and not have to create masks.
There's also a link in this thread that describes a way to create the
masks, from your images, so could save you some work, and can be used
as a substitute for Transparentblt on Win9x platforms.
http://www.xtremevbtalk.com/showthr...=transparentblt
Assuming you can't use or don't want to use transparentblt, or the
method mentioned in the link above, then you will need to create your
masks.
Since your rockets are on a black background you will have to "Or" the
image to draw it. That means you will want to "And" the mask to
prepare for the image. Since you are "And"ing the mask, the mask needs
to be a white background with a black silouette (I probably didn't spell
that correctly) of your rocket images.
Once you have your images and masks, then what you probably want to
do in this game is:
1. Save the background of the rectangle where you are going to blt your
rocket (blt from the form to a picbox).
2. BitBlt the mask to the form using "And" (vbSrcAnd)
3. BitBlt the image to the form using "OR" (vbSrcPaint)
4. me.refresh (Autoredraw must be true on your form to allow bliting
from it, to save your background).
When it's time to move the rocket,
5. BitBlt the saved background back to it's original position to erase the
rocket.
6. Goto step 1.
The response is probably moot now, since rpgnewbie, I believe, has
covered the bases.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |
|