ok i did some wokin and iv come alon quite nicely ((right...))
anyhoo im making a new game and i have some questions.
i have an image in a picture box, and i would like for it to do the following:
when i press the up arrow on the keyboard the img would go up until it reaches the top of the picture box.
when i press the down arrow i would like the img to go down until it reaches the bottom of the picture box.
____
im not sure how to assign differnt keys, such as the up arrow and down arrow, i know it has somthing to do with the keydown and keyup code area but im lost after that....
the arrow keys are:
37 up
38 right
39 down
40 left
as far as moveing the image in the picbox the easyiest way would probaly be to use the bitblt api call
if you dont know how it works i copyed the text from vbapi.com(currently shut down but i downloaded the whole site)
BitBlt Function
Declare Function BitBlt Lib "gdi32.dll" (ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal dwRop As Long) As Long
Platforms
Windows 95: Supported.
Windows 98: Supported.
Windows NT: Requires Windows NT 3.1 or later.
Windows 2000: Supported.
Windows CE: Requires Windows CE 1.0 or later.
Description & Usage
BitBlt performs a bit-block transfer of a rectangular portion of an image from one device to another. The dimensions of the transfered rectangle are perfectly preserved. The function can perform a variety of raster operations to transfer the block from the source device to the target device.
Return Value
If an error occured, the function returns 0 (Windows NT, 2000: use GetLastError to get the error code). If successful, the function returns a non-zero value.
Visual Basic-Specific Issues
None.
Parameters
hdcDest
A handle to the device context of the device which receives the transfered image block.
nXDest
The x-coordinate of the point to position the upper-left corner of the transfered image block.
nYDest
The y-coordinate of the point to position the upper-left corner of the transfered image block.
nWidth
The width in pixels of the image block.
nHeight
The height in pixels of the image block.
hdcSrc
A handle to the device context of the device which contains the image block to transfer.
nXSrc
The x-coordinate of the upper-left corner of the image block to transfer.
nYSrc
The y-coordinate of the upper-left corner of the image block to transfer.
dwRop
One of the following flags identifying the raster operation to use to transfer the image block. Each raster operation uses the RGB color value of the source and/or target pixel to determine the new color of the target pixel.
BLACKNESS
Fill the destination rectangle with the color whose index is 0 in the physical palette (which is black by default).
CAPTUREBLT
Windows 98, 2000: Include any windows layered on top of the window being used in the resulting image.
DSTINVERT
Invert the colors in the destination rectangle.
MERGECOPY
Merge the colors of the source rectangle with the specified pattern using the bitwise AND operator.
MERGEPAINT
Merge the colors of the inverted source rectangle with the colors of the destination rectangle using the bitwise OR operator.
NOMIRRORBITMAP
Windows 98, 2000: Prevent the bitmap from being mirrored.
NOTSRCCOPY
Copy the inverted source rectangle to the destination rectangle.
NOTSRCERASE
Combine the colors of the source and destination rectangles using the bitwise OR operator and then invert the resulting color.
PATCOPY
Copy the specified pattern into the destination bitmap.
PATINVERT
Combine the colors of the specified pattern with the colors of the destination rectangle using the bitwise XOR operator.
PATPAINT
Combine the colors of the specified pattern with the colors of the inverted source rectangle using the bitwise OR operator. Combine the result of that operation with the colors of the destination rectangle using the bitwise OR operator.
SRCAND
Combine the colors of the source and destination rectangles using the bitwise AND operator.
SRCCOPY
Copy the source rectangle directly into the destination rectangle.
SRCERASE
Combine the inverted colors of the destination rectangle with the colors of the source rectange using the bitwise AND operator.
SRCINVERT
Combine the colors of the source and destination rectangles using the bitwise XOR operator.
SRCPAINT
Combine the colors of the source and destination rectangles using the bitwise OR operator.
WHITENESS
Fill the destination rectangle with the color whose index is 1 in the physical palette (which is white by default).
' This code is licensed according to the terms and conditions listed here.
' Copy a rectanglular image from window Form1 to window Form2
' exactly (using SRCCOPY). The rectangle has a width of 100 and a height of
' 50. The upper-left corner of the source block is (350, 250); the block
' is placed at (0,0) in Form2.
Dim retval As Long ' return value
' Transfer the image exactly as described above.
retval = BitBlt(Form2.hDC, 0, 0, 100, 50, Form1.hDC, 350, 250, SRCCOPY)
this should get you started post again if you need more help
Originally posted by SmashX im sorry i dident see that.
um i got a new question.
where would i put that code?
i have it in a loop..but...where do i put that?
If you want to use a loop, you just make a sub called GameLoop or what ever, and call the sub when your game is starting....Or you could use a timer, and skip the loop, and set the timer enabled property to true when you want your game to start...
is there a way to get rid of that pic that says there the whole time. cuz there is one img that moves and another that just stays there. i dont want that to be visible.
Originally posted by SmashX it was the picture box.
after i got rid of that it worked fine.
is there a way to get rid of that pic that says there the whole time. cuz there is one img that moves and another that just stays there. i dont want that to be visible.
((BTW: im adding you onto my credits page. ))
In my example it is a two player game...you move the other picture using A,S,D,W. If you don't want that. You can delete the picture box, and delete this lines in your code...:
Sorry NoteMe,
I wasn't trying to outsmart you, I just figured he would be stalled by the amount of code you gave as a start. My intention was to get him started and as you said
see if you can learn something
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button Wait, I'm too old to hurry!
Originally posted by opus Sorry NoteMe,
I wasn't trying to outsmart you, I just figured he would be stalled by the amount of code you gave as a start. My intention was to get him started and as you said
I wasn't blaming you at all...just wanted to make a point about that he already had got the answers to all his question if he just looked at it...
Yes exactly, so now you have the code to move the guy, and you have the code to shoot a laser from his hand...so no you have to put it togheter...that sould be no match for you...