|
-
Jan 5th, 2002, 08:37 PM
#1
Thread Starter
Banned
move a shape with arrows
how do i make a shape move to the right and the left when u press the arrows on the keyboard? THANKS!
-
Jan 5th, 2002, 09:06 PM
#2
Set the KeyPreview property of the Form to True and use code simular to the following in the KeyDown event of the form.
VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDown
Shape1.Top = Shape1.Top + 45 '3 pixels
Case vbKeyUp
Shape1.Top = Shape1.Top - 45 '3 pixels
Case vbKeyLeft
Shape1.Left = Shape1.Left - 45
Case vbKeyRight
Shape1.Left = Shape1.Left + 45
End Select
End Sub
Best regards
-
Jan 5th, 2002, 09:08 PM
#3
Member
Rather than using 45 for 3 pixels, I suggest (with all respect to Joacim ):
VB Code:
Screen.TwipsPerPixelX * 3
' and
Screen.TwipsPerPixelY * 3
Twips are dumb.
-
Jan 5th, 2002, 09:14 PM
#4
Frenzied Member
The picture would flicker like mad though. would it not?
How would you resolve that?
"If at first you don't succeed, then skydiving is not for you"
-
Jan 5th, 2002, 09:16 PM
#5
PowerPoster
Try setting the autoredraw property to true on the form. Just one way, as there are a few others..
-
Jan 5th, 2002, 09:17 PM
#6
Originally posted by filburt1
Rather than using 45 for 3 pixels, I suggest (with all respect to Joacim ):
VB Code:
Screen.TwipsPerPixelX * 3
' and
Screen.TwipsPerPixelY * 3
Twips are dumb.
I agree, i'm just drunk and lazy right now
-
Jan 5th, 2002, 09:17 PM
#7
Member
If you use either LockWindowUpdate Me.hwnd (see the API viewer for the declaration) or use BitBlt you can get rid of the flicker:
VB Code:
LockWindowUpdate Me.hwnd
' move stuff
LockWindowUpdate 0 ' I think
-
Jan 5th, 2002, 09:25 PM
#8
Hey filbert1!
Why have you stoped using your turtles in your avitars?
I don’t really appreciate that you’re now using a picture of my girlfriend
-
Jan 5th, 2002, 09:27 PM
#9
Member
-
Jan 5th, 2002, 09:30 PM
#10
I know that she's hot because I'm sleeping with her (I wish )
-
Jan 5th, 2002, 09:32 PM
#11
Frenzied Member
You sleep Joacim?? 
When?.. you're always on here.
"If at first you don't succeed, then skydiving is not for you"
-
Jan 5th, 2002, 09:33 PM
#12
Member
Originally posted by Joacim Andersson
I know that she's hot because I'm sleeping with her (I wish )
You are so drunk tonight.
-
Jan 5th, 2002, 09:41 PM
#13
-
Jan 5th, 2002, 09:43 PM
#14
Here is a old project I have made just to show you how to move a shape.
-
Jan 6th, 2002, 11:14 AM
#15
Thread Starter
Banned
I tried!~
I used this code and named my shape "player" but it doesnt move!
Private Sub player_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyRight Then
player.Left = player.Left + 30
End If
If KeyCode = vbKeyLeft Then
player.Left = player.Left - 30
End If
If KeyCode = vbKeyUp Then
If player.Top < Line2.Y1 Then Exit Sub
player.Top = player.Top - 30
End If
If KeyCode = vbKeyDown Then
If (player.Top + player.Height) > Line1.Y1 Then Exit Sub
player.Top = player.Top + 30
End If
End Sub
-
Jan 6th, 2002, 11:22 AM
#16
You should use the Form_KeyDown event and not the player_KeyDown event.
You also have to set the KeyPreview property of the Form to True.
Best regards
-
Jan 6th, 2002, 01:19 PM
#17
Thread Starter
Banned
thanks
thanks, now it works
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|