Would Xtreme and Chris1232 Come Here

Bunkey23
12-03-2000, 11:58 AM
Hi. you guys seem to know how to program games. I would like to know how you learned all this stuff. if you learned from the internet can you tell me the web addresses that you were at i would really appreciate it.

Xtreme
12-04-2000, 06:39 AM
do you mean direct x or something a little easier?

Bunkey23
12-05-2000, 04:40 AM
what do you mean???
Right now i am using BitBlt and I dont know a thing about it. i read the stuff at vbexplorer but i didnt understand it.
so whatever you can do to help is fine.
Thanx

Xtreme
12-05-2000, 06:33 AM
Ok, just realize that i am doing this at school right now so i cant exactly give you my source code (because it is at home :)) But what i will do is take a tutorial at vb explorer and simplify it. I cant profess to know the specifics of bitblt but i do know how to use it so here goes.

I am refering to the Graphics tutorial and Drawing and animation 1

Ok for starters whenever you use BitBlt always declare this (post it into your code :))

Put this at the start of the code in your form (right under Option Explicit)

Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hSrcDC As Long, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
ByVal dwRop As Long) As Long

This is really just 1 long line its just that it wont fit that way in this text box.

now lets look at the code within the ( ) of the function:

hDestDC - This is the handle to the DC (ok this might not be correct but i read somewhere that every window has a handle even the picture boxes that you put on the form so what goes in this statement would be what object you want the picture to appear on.

x and y - these are the x and y coordinates of where you want the picture to appear.

nWidth and nHeigth - Dont quote me on this but i beleave it is the width and height of the picture you are using. :)

hSrcDC - this is the handle to the source DC that would be where the actual picture is stored. Now perhaps you can see why they used a picture box. By assigning a picture to a picture box you can then put the handle to the picture box in this statement.

xSource and ySource - Funny enough i never used these :) you might just want to change them around a little bit to see what happensn. I believe for regular BitBlt just leave it at 0, 0 (it might have something to do with stretching the picture so just leave it at 0)

dwRop - alright the web site probabely has a better explanation of this :) but this is the MAGICAL KEYWORD (Just kiddin). This a statement that can have the following values:

vbBlackness Sets destination = 0 (Black)

vbDstInvert Inverts the destination rectangle (NOT Destination)

vbMergeCopy Combines the source with the destination using AND

vbMergePaint Combines the source with the destination using OR

vbNotSrcCopy Inverts the source and then copies it to destination

vbNotSrcErase Inverts the result of combining the source and destination using OR

vbSrcAnd Combines the source and the destination with the AND operator

vbSrcCopy Copies the source directly to the destination

vbSrcErase Combines the inverted destination with the source using AND

vbSrcInvert Combines source and destination with XOR

vbSrcPaint Combines the source and the destination with OR

vbWhiteness Destination is set to white

Ok now let me tell you that i certainly have not used all of these statements. Dont let them overwhelm you!

the one we will use is this: vbSrcCopy

Now with all this information we will start with coding.

For the form you will need 1 picture box Called PictureBox1
The Form should be called Form1
---------------------------------------------
set Form1's Properties as followes:

Set ScaleMode from TWIP to Pixles
Set AutoRedraw to True
-------------------------------------
Set PictureBox1 properties to:

Set ScaleMode from TWIP to Pixles
Set AutoRedraw to True
Set AutoSize to True
Load the picture into the picture box
---------------------------------------

Form1 Form_Load()

Me.Cls ''''''Dont let the Me condfuse you i dont know where the statement ''derives from but it is a universal way of saying the Form (so it could be ''replaced by Form1.Cls !!!!!!
'' Why do this?? Because when you are doing animation you would want to clear the ''screen before you redrew the next picture or you would get a blur of the image ''(Cls stands for Clear Screen)

''''' Now here is the Gold !:)

BitBlt Form1.hDC, 0, 0, PictureBox1.ScaleWidth, _

PictureBox1.ScaleHeight, PictureBox1.hDC, 0, 0, vbSrcCopy

''chose vbSrcCopy because the only thing we want to do is to copy the image from ''Picturebox1 and display it on Form1

''Oh and the PictureBox1.ScaleWidth statements derive from the picture box ''control
''Just start typing PictureBox1.S Once you put in the dot and type S a drop ''box will come down of available properties. Just finish typeing ScaleWidth or ''select it from the list!!


End sub

Please dont forget that this is one line

BitBlt Form1.hDC, 0, 0, PicctureBox1.ScaleWidth, _
PictureBox1.ScaleHeight, PictureBox1.hDC, 0, 0, vbSrcCopy

just back space over the __

The great thing about BitBlt is that you can generally just copy the code for anohter image and just change a couple of the properties!!!!



Now if you want to achieve transparency here is what you should do:

BitBlt Form1.hDC, 0, 0, PicctureBox1.ScaleWidth, _
PictureBox1.ScaleHeight, PictureBox1.hDC, 0, 0, vbSrcAnd

BitBlt Form1.hDC, 0, 0, PicctureBox2.ScaleWidth, _
PictureBox2.ScaleHeight, PictureBox2.hDC, 0, 0, vbSrcPaste

Now notice i am using 2 different pictures and 2 different picture boxes
One picture will have to have a black background with everything else colored in and the onther picture will have to have a white background with the the colored parts in black.

I will have to give you an example of this becasuse i do not remember which picture should go into which picture box :)

In the meantime you can experiment with it and please let me know if you run into any errors ( you will also need to supply me with the code you used ).



''''''' I will try to give you an example in a program but it might take me till Wednessday to do it. Till then if you have any questions please let me know.
ENJOY!!!


Please let me repeat this is a simple overview that i have created using the tutorial from vb explorer as my source.

check it out at:
http://www.vbexplorer.com/tutorials.asp<P ID="edit"><FONT SIZE=-1><EM>Edited by xtreme on 12/05/00 07:44 AM (server time).</EM></FONT></P>

DeMaster
12-05-2000, 08:44 AM
I found this Primer helped me to understand bitblt more than anything... Hope it helps you as much as it did me... If you have any particular questions I would be happy to help...

<a href="http://www.vbexplorer.com/library/bitbltprimer.htm">http://www.vbexplorer.com/library/bitbltprimer.htm</a>

Duane

Programming... The expression of true creativity bound only to the limitations of your mind...

Bunkey23
12-05-2000, 04:04 PM
i was wondering if you could make up those overviews for the other tutorials there. (only the animation and game control. I can do the soundz)

Xtreme
12-06-2000, 05:56 AM
Exactly which tutorials? (there are three on animation and drawing of which i have previousley covered the first one) Tell me the name of the exact one you want.

Bunkey23
12-06-2000, 03:45 PM
I would like Animation 2 and 3
then I would like the control ones.
the ones that i would like the most are Animation 2 and 3. I can figure out the controls. thanx

Xtreme
12-07-2000, 06:43 AM
Alright lets begin :)

First off i (And you probabely wont need to use BackBuffering Autoredraw and Refresh is fine to use) havent used Backbuffering. However when you learn how to use Direct X(a faster way of doing animation and effects etc) Then you will be using Backbuffers. But again you probabely wont need to know this method.

Ok this is going to be hard because i dont have vb on my school computer so i dont know what his sample looks like but here is the basis for the Auto Redraw method:

First to do animation you have to clear the screen so that there is no blur with the image.

Form1.Cls

'Second bo your blitting(covered in my previous sumary)
'Draw the mask
BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picMask.hDC,0, 0, vbSrcAnd

'Draw the sprite
BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picSprite.hDC, 0, 0, vbSrcPaint



''' Now refresh the screen (You must have the form1 and both picuture boxes set ''' to AUTOREDRAW
Form1.Refresh

Now im guessing this is the part that is tripping you up but once you understand it is amazing what you can do (and how simple it is ;))

First Say you have a bitmap that looks like this

************************************************
*!!!!!!!*!!!!!!!*!!!!!!!*!!!!!!!*!!!!!!!*!!!!!!*
*!!!!!!!*!!!!!!!*!!!!!!!*!!!!!!!*!!!!!!!*!!!!!!*
************************************************

That would be 6 different squares containing each a piece of animation!!

Now using that one picture box, how do we acces all those frames IDIVIDUALLY!

The answer is in this statment:
''This!!''
BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picMask.hDC, 0, 0, vbSrcAnd
''''Dont forget your other bitblt Sprite!

Those two zeroes are the key to this manipulation.
What....Why????????

Well....................
Look at my pretty picture again.


Sorry dont pay attention to these graphic the computer im at screwed them up (th spaces arent spaced it is suppossed to be different squares!)
************************************************
* * * * * * *
* * * * * * *
************************************************

The first 0 means that the STARTING x value of the picture should begin at x coordinate 0.
The second 0 means that the STARTING y value of hte picture should begin at y coordinate 0.

0***********************************************
* * * * * * *
* * * * * * *
************************************************

Now you are probabely wondering, "If i set the beginning point of the x value for the Bitmap then what stops it from continuing all the way Until the end of the bitmap resulting in several animation blts in one scene. Well this is not true. look at the code again:

''''Do you see it???? HERE!!!!!
BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picMask.hDC, 0, 0, vbSrcAnd

So with the Sprite Width not according to a picture box means that you can set the Width. So for my example the width would be 9!

Therefore on this statment:
Form1.Cls

BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picMask.hDC, Xanim, 0, vbSrcAnd
''''Dont forget your other bitblt Sprite!

Form1.Refresh

Xanim = Xanim + 9

0OOOOOOOO***************************************
O O * * * * *
O O * * * * *
OOOOOOOOO***************************************

This would be the part that would be blitted.

Subsiquently if you called the same statement agian:

Form1.Cls

BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picMask.hDC, Xanim, 0, vbSrcAnd
''''Dont forget your other bitblt Sprite!\

Form1.Refresh

Xanim = Xanim + 9

THEN:

********OOOOOOOOOO***********************************
* O O * * * *
* O O * * * *
********OOOOOOOOOO***********************************

You would now blit the next square of the picture!!!

Now put in an if so that you stop at the last frame:


Form1.Cls

BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picMask.hDC, Xanim, 0, vbSrcAnd
''''Dont forget your other bitblt Sprite!


Form1.Refresh

Xanim = Xanim + 9

''''' The total length of the entire bitmap

MaxLength = 54

IF Xanmim = MaxLength THEN
Xanim = 0
END IF

Now if you wanted a bitmap that had frames that were both up and down as well as left and right we would change the second 0 value accordingly.

''' OH!!! And dont forget to set BOTH the Form and the picture boxes to AUTOREDRAW TRUE!!!!!!!

'''One more thing you might be wondering why the blt statement looks different so let me reitterate on the method for this example.

Alright we are still using 2 picture boxes!!!!(Notice the last hDC or handle)
the author of the tutorial calls it picMask


BitBlt Me.hDC, X, Y, SpriteWidth, SpriteHeight, picMask.hDC, Xanim, 0, vbSrcAnd



Are you asking why not use picMask.ScaleWidth? Well i hope that was answere above.
The only reason why we used that last time was for simplicity. IT could just as well be any integer 9 ro 25 or 40 whatever the width is. The only thing that you need the picture box for is for the handle at the end of the bitblt statement.

AW *!&@!#($*!@!!!!!!!

I just realized that this code showes you how to stretch an image. IT is with a seperate statemnt. You wont believe how log i had tried to figure this out! Well.... Now i know!

Ok so keep in mind this is a different statement than bitblt, here it is:

StretchBlt Me.hdc, X, Y, Stretch, Stretch, picMask.hdc, 0, 0, _
SpriteWidth, SpriteHeight, vbSrcAnd

Ok since you know (I HOPE) how to do normal bitblt hopefully you understand this statemnt

StretchBlt Me.hdc, X, Y, Stretch, Stretch, picMask.hdc, 0, 0, _
SpriteWidth, SpriteHeight, vbSrcAnd

OK so X, Y are screen coordinates
Stretch, Stretch must be x and y expansion of the bitmap (this is only a guess since the tutorial site doesnt seem to explain it :))
Then you have your picture box hdc

0, 0 I assume is the starting x and y values for the picture (remember the Animation! sample)

Then you have your spriteWidth and SpriteHeigth

I hope all this helps!!!

Happy programming!
<P ID="edit"><FONT SIZE=-1><EM>Edited by xtreme on 12/07/00 08:09 AM (server time).</EM></FONT></P>

Xtreme
12-07-2000, 07:01 AM
Ok just didnt want to take up to much space here is the rest of Animation 2 Summary.

P.S. I certainly dont want to take away any of the credit from the person that created the tutorial that i am simplifying. You should read it first then read my summary:) it is at vb explorer Under Graphics and Animation Tutorials and then Animation 2!

Ok now please realize that i have never used this technique (Must have thought it was too hard ;)

Alrighty first you have probably been wondering what the *@#(%@! the .hDC is.
.hDC stands for Handle to the Device Context. When you need to use a specific Device Context you have to grab its HANDLE. so you see when you called Picture1.hDC you were grabbing the HANDLE of the picture1 boxes Device Context!!!

Alright now start thinking of a custom DC as a blank sheet of paper and think of your computer screen as another sheet of paper.

Ok First we must



Public Function GenerateDC(FileName As String) As Long
''' declare some variables
Dim DC As Long
Dim handle_to_Bitmap As Long

''
'Create a Device Context, compatible with the screen
''' This is a call (i believe correct me if im wrong) to the api function
''' It creates a compatable DC one that is compatable with your screen and loads ''that DC or blank sheet of paper into DC


DC = CreateCompatibleDC(0)

''' Thsi is basically did it WORK????? if not exit
If DC < 1 Then
GenerateDC = 0
Exit Function
End If

'Load the image....
'This function is not supported under NT, there you can not
'specify the LR_LOADFROMFILE flag
handle_to_Bitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
'''
''' Did it work??
If hBitmap = 0 Then 'Failure in loading bitmap
DeleteDC DC
GenerateDC = 0
Exit Function
End If

'''Assign the Bitmap to the Device Context(draw the picture onto the blank paper)
SelectObject DC, hBitmap


'Return the device context (I dont really know probable restore the memory
GenerateDC = DC

'''Delete the bitmap handle object (agian not sure but i guess now that the ''bitmap is attach to the HDC you can get reid of all the tools it took the tools '''to create it... like cleaning up your crayons and markers :)

DeleteObject hBitmap
End Function

Now
'''' Again im afraid i dont know why see the tutorial for help.. download the ample and play with it until you understand it.... I believe this is probabely called after the form unload, that way you dont waste memory.


Private Function DeleteGeneratedDC(DC As Long) As Long

If DC > 0 Then
DeleteGeneratedDC = DeleteDC(DC)
Else
DeleteGeneratedDC = 0
End If

End Function

Enjoy :)

Xtreme
12-07-2000, 07:05 AM
Oh and incase you are wondering what the hDC is used for once you have created it, it replaces the Picture box and the statement picture1.hDC by DC.hDC.

Sorry but this is only a guess i dont actually have the code to test this theory but i believe this is the way it works. Please download the tutorials file to help you with the specifics.

Bunkey23
12-08-2000, 04:19 PM
hi again,
I dont need to know the animation3 because i am going to try the direct draw thing. I know it is harder but the sprites are to confusing in Bitblt. I dont understand how to combine a sprite and mask. so i am gonna try directx and direct draw.

chris1234
12-11-2000, 02:25 AM
sorry I didnt reply I didnt check this site for ages.
I also changed my name because I forgot my password.
well I guess Xtreme told you all you wanted to know so just email me if ya want anything.

Good luck with your game :-)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum