[RESOLVED] BitBlt issue smearing the character on a moving background...
I made visible the Character and CharacterMask for referencing
VB6
Windows 7
I am using BitBlt to move the map behind the character. I am also using BitBlt to draw the character. The character is animating (running). So, to keep the character centered, I am having to continually adjust the X and Y of the character, which is not the problem. The problem is the smearing I am getting. The code is in a Timer:
Code:
If (timerMapMover.Tag = "NORTH") And (MoveMapY < 0) Then
MoveMapY = MoveMapY + 1
myCharacter.Picture = LoadResPicture("NORTH" & MyAni, 0)
MakeMask myCharacter, myCharacterMask, CLng(vbBlack), CLng(vbWhite), CLng(vbBlack)
BltTheCharacter myBuffer, myCharacter, myCharacterMask, ConvertTwipsToPixelsX(Me.Width / 2) - MoveMapX, ConvertTwipsToPixelsY(Me.Height / 2) - MoveMapY
BltFinal myStage, myBuffer, MoveMapX, MoveMapY
End If
myCharacter is my Hero
myCharacterMask is the masked version of my Hero
myBuffer is the buffer PictureBox
myStage is where everything is BitBlt'd once it is all combined in the buffer
Obviously I am moving North, therefore the map is moving down to give the appearance of the character moving North.
I am using images loaded in a .res file.
MakeMask calls a routine to create the mask.
Re: BitBlt issue smearing the character on a moving background...
Is this the same problem you had in your other thread? I thought you had that taken care of based on what you were told or is this a totally different problem.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: BitBlt issue smearing the character on a moving background...
I believe Arnoutdv is correct. Anytime you move a drawing by BitBlt'ing it you need to first save the area you will BitBlt to then BitBlt to that position. Now save the next area you will BitBlt to and then again BitBlt to that position then restore the area you BitBlt from.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: BitBlt issue smearing the character on a moving background...
edit: [I didn't see the first post, I thought this was a continuation of your ealier post... It certainly looks like you're using a tile based map, but maybe it was tiled offline, and you just moving a large map. In any case, perhaps the post can still be useful].
Or, if you were doing a tile based map, you would probably be redrawing all the background because you would be be bitblting all the tiles of your background as you move.
I did a short example for someone around 7 to 8 years ago. I did a search and found it, and will attach it. It doesn't do much. It was just thown to gether for someone who provided the car images to show moving the car around a tile based map. Since I didn't have a tile set, and wasn't going to take the time to build a map, I just "generate" four random tiles of different color and assign them randomly to the "map".
In this example, the car will move toward the center of the window, and then remain there as the map moves by, until an edge is reached, in which case the car will move out of the center area and out to the edge of the window. I found a zip file of it, a little over 7 years old and didn't retry it to make sure it works but I wouldn't have zipped it up if I didn't post it back then, so should work. You use the up key to go forward, and the down key to go backwards, and the left,right keys to turn.
Last edited by passel; Jan 17th, 2014 at 01:20 PM.
Re: BitBlt issue smearing the character on a moving background...
Just a note , to use picturebox.cls before drawing anything. Use once.
I also recommend using without a timer for drawing.
Public Const SRCAND = (&H8800C6) ' Use for your Mask , White Background
Public Const SRCPAINT = (&HEE0086) 'Use for your Picture , Black Background
Public Const BLACKNESS = (&H42) 'All Black
Public Const DSINVERT = (&H550009) 'Invert.
Public Const MERGECOPY = (&HC000CA) 'Pattern and the source
Public Const MERGEPAINT = (&HBB0226) 'Inverted source
Public Const NOTSRCCOPY = (&H330008) 'Copies the inverted source bitmap to the destination.
Public Const NOTSRCERASE = (&H1100A6) 'Inverts the result of combining the destination.
Public Const PATCOPY = (&HF00021) 'Copies the pattern to the destination bitmap.
Public Const PATINVERT = (&H5A0049) 'Combines the destination bitmap with the pattern.
Public Const PATPAINT = (&HFB0A09) 'Combines the inverted source bitmap with the pattern.
Public Const SRCAND = (&H8800C6) 'Combines pixels of the destination and source bitmap.
Public Const SRCCOPY = (&HCC0020) 'Copies the source bitmap to destination bitmap.
Public Const SRCERASE = (&H4400328) 'Inverts the destination bitmap and combine.
Public Const SRCINVERT = (&H660046) 'Combines pixels of the destination and source bitmap
Public Const SRCPAINT = (&HEE0086) 'Combines pixels of the destination and source bitmap
Public Const WHITENESS = (&HFF0062) 'Turns all output white.
Just noting that if you havent done too much which i can see that maybe you havent.
I would try checking out my post here for reference. Would be good for any game.
Re: BitBlt issue smearing the character on a moving background...
C080,
Are you sure you're posting in the correct thread? What's with this picturebox.cls
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: BitBlt issue smearing the character on a moving background...
Im sorry , i wasnt specific. By not clearing what you are drawing to , it causes the smearing , whether form or picturebox.
I used this just as a general outline of any and wasnt precise.
Re: BitBlt issue smearing the character on a moving background...
Well, anyway, that has already been mentioned previously
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: BitBlt issue smearing the character on a moving background...
Just a note when blitting , the first blit is always on the bottom , behind the next , so if you do a SRCCOPY blit of a picture , that just copys the picture then use SRCAND and SCCPAINT for your pictures with masks , you can test this.
Useful to know when game programming and wanting something in the background behind a character for sidescroll or to make something hidden.
If you
You could have a mainLoop which does all the drawing with coordinates and draws off screen then comes into focus. Ive noticed that with gdi , without drawing everything at once you come to a point where the game hangs or skips around. At some point or another.
So putting all your drawing into one loop makes this simple and the only code you would need is where they will be drawn.
Just a note.
I do to only help and i dont know everything , i state what i do from experience as i know i have much to learn , even ever so little.
Sometimes mentioning something in a different manor gets a better interpretation.
Re: BitBlt issue smearing the character on a moving background...
Originally Posted by c080
Just a note , to use picturebox.cls before drawing anything. Use once.
I also recommend using without a timer for drawing.
Public Const SRCAND = (&H8800C6) ' Use for your Mask , White Background
Public Const SRCPAINT = (&HEE0086) 'Use for your Picture , Black Background
Public Const BLACKNESS = (&H42) 'All Black
Public Const DSINVERT = (&H550009) 'Invert.
Public Const MERGECOPY = (&HC000CA) 'Pattern and the source
Public Const MERGEPAINT = (&HBB0226) 'Inverted source
Public Const NOTSRCCOPY = (&H330008) 'Copies the inverted source bitmap to the destination.
Public Const NOTSRCERASE = (&H1100A6) 'Inverts the result of combining the destination.
Public Const PATCOPY = (&HF00021) 'Copies the pattern to the destination bitmap.
Public Const PATINVERT = (&H5A0049) 'Combines the destination bitmap with the pattern.
Public Const PATPAINT = (&HFB0A09) 'Combines the inverted source bitmap with the pattern.
Public Const SRCAND = (&H8800C6) 'Combines pixels of the destination and source bitmap.
Public Const SRCCOPY = (&HCC0020) 'Copies the source bitmap to destination bitmap.
Public Const SRCERASE = (&H4400328) 'Inverts the destination bitmap and combine.
Public Const SRCINVERT = (&H660046) 'Combines pixels of the destination and source bitmap
Public Const SRCPAINT = (&HEE0086) 'Combines pixels of the destination and source bitmap
Public Const WHITENESS = (&HFF0062) 'Turns all output white.
Just noting that if you havent done too much which i can see that maybe you havent.
I would try checking out my post here for reference. Would be good for any game.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
Shutdown
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Shutdown
End Sub
Another thing is that you shouldn't use BitBlt for making games with as it is a royal pain to work with. Your better off either using TransparentBlt which doesnt require a mask for transparency, or step into the realm of DirectX in VB. With DirectX, you can make beautiful enriched games both in 2D and 3D such as these:
I have lots and lots of DirectX examples in my signature
Re: BitBlt issue smearing the character on a moving background...
This simple example shows you how to move an image across a canvas using BitBlt API. This example uses a Picturebox control where you move the image using the command buttons or the up, down, left, and right keyboard keys.
The basic steps to move an image are:
1) Save the rectangle area from the Picturebox the size of the rectangle of the original image.
2) BitBlt the original image from it's source to that area on the Picturebox. It is better to use TransparentBlt instead of BitBlt because it does not require that you use masking to make image transparent.
3) Restore the area that was saved
4) Set next position
5) Save the area that represents the next position you want to move the image to
6) BitBlt image to next position
Repeat at Step 3
The attached project use this method.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: BitBlt issue smearing the character on a moving background...
Here's another example. This one uses BitBlt to move the balls so it requires masking. The balls are moved using the mouse pointer and can be moved anywhere on the screen
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: BitBlt issue smearing the character on a moving background...
I also recommend using without a timer for drawing. 'Quoting myself
'See Above.
My attached Link , shows a thread ' Loop from that post. = Boolean , that is continuous. Until false.
No Timer.