Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Hello,I come from China!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

EmilMatthew
Squire

China
11 Posts

Posted - Jun 26 2004 :  07:22:58 AM  Show Profile  Reply with Quote
Desinging a good game all by myself is always a dream in my mind.
When I touch VB ,I become to know that the time for my dream to become true is nearer.
On Chinese Website ,there are many forums about VB,but rarely
about using VB and DIRECT X to design a game .
Now,I am a beginner of Direct X with VB designing.
I feel very excited to be here.
Ok ,I want to ask my first question now:(maybe it is not about directx but it's really about game design)
How to use "up","Down" ,"Left" and "Right" button to control a object (for example,a "command" button)
I wrote my programme in the "form_keydown"event
the main part is like this>>

SELECT CASE KEYCODE
CASE VbKeydown
command1.top=command1.top+5
case vbkeyup
command1.top=command1.top-5
case vbkeyleft
command1.left=command1.left-5
case vbkeyright
command1.left=command1.left-5
end select
>>>>>
the result is that I failed to use these button to control the objects to move .
However,when I use the up ,down,left and right on the number keys (I hope you know what I mean ,the number keys means the right part on the keyboard)I use their "Keycode " in the "select case".I became successfully to control the object.

So ,who can tell me how to use "up","Down" ,"Left" and "Right" button to control a object ?
Thank you


Edited by - EmilMatthew on Jun 26 2004 07:26:18 AM

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 26 2004 :  09:44:36 AM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
It's because VB is intercepting those key presses and it is moving the "control focus" to different objects on the form.

If you want to see your command button move, then follow these steps:
1. Set Form1.KeyPreview = True
2. Create a PictureBox on the form along with your Command button.
3. Start the program.
4. Click on the picturebox to give it the focus.

What happens in this example is that the picture box won't switch the focus to another control when using the arrow keys.

Also, here is a slight correction for the code you're using
With Command1  
    Select Case KeyCode  
        Case vbKeyDown  
            .Top = .Top + Screen.TwipsPerPixelY  
        Case vbKeyUp  
            .Top = .Top - Screen.TwipsPerPixelY  
        Case vbKeyLeft  
            .Left = .Left - Screen.TwipsPerPixelX  
        Case vbKeyRight  
            .Left = .Left + Screen.TwipsPerPixelX  
    End Select
End With


Go to Top of Page

Dan
Squire

United Kingdom
29 Posts

Posted - Jun 26 2004 :  11:33:13 AM  Show Profile  Visit Dan's Homepage  Reply with Quote
Check out the tutorial on Directx4vb:
http://216.5.163.53/DirectX4VB/Tutorials/DirectX8/IN_Lesson01.asp

A great step by step guide to getting keyboard presses using directx.


Go to Top of Page

EmilMatthew
Squire

China
11 Posts

Posted - Jun 27 2004 :  04:56:15 AM  Show Profile  Reply with Quote
Yeah,I have gotta it .Thank you two so much.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.12 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.