directx input

destress
06-22-2002, 01:27 PM
hey there,

i'm actually creating a car racing game and i need some help for the direct input codes.... my game does not seem to reconize these codes as my object does not move. Could someone please check the code.... another question is how do i assign the object to move left, right up and down


'~~~~~DIRECT INPUT~~~~~
Dim di As DirectInput
Dim diDEV As DirectInputDevice
Dim diState As DIKEYBOARDSTATE
Dim iKeyCounter As Integer

Public Sub Do_Keys()
Set di = dx.DirectInputCreate()
Set diDEV = di.CreateDevice("GUID_SysKeyboard")
diDEV.SetCommonDataFormat DIFORMAT_KEYBOARD
diDEV.SetCooperativeLevel Me.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
diDEV.Acquire
diDEV.GetDeviceStateKeyboard diState

If diState.Key(DIK_ESCAPE) <> 0 Then
DxEnd
End If

'Check right key press
If diState.Key(DIK_RIGHT) <> 0 Then
Car.ShiftRight
End If

'Check left key press
If diState.Key(DIK_LEFT) <> 0 Then
Car.ShiftLeft
End If

'Check Up key press
If diState.Key(DIK_UP) <> 0 Then
Car.ShiftUP
End If

'Check left key press
If diState.Key(DIK_DOWN) <> 0 Then
Car.ShiftDown
End If
End Sub

Your help is greatly appreaciated
thanks !

Squirm
06-22-2002, 02:22 PM
It is normal to initialise DI once at the start of the game, then poll it as required in the game. The sub you pasted above both initialises and polls the keyboard. You need to separate the initialisation code into a sub which is called once, and the key checking into a sub which is called in a loop.

destress
06-23-2002, 01:53 AM
hey there,

thanks for ur suggestion, it works partially i have another question....how do i assign my object to move according to the keystrokes


Thanks again for ur help

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum