tailieunhanh - microsoft visual basic game programming for teens phần 7

bây giờ cuối cùng thông qua kinh nghiệm. Chỉ cần cố gắng thử nghiệm với các giá trị khác nhau hex trong chương trình SpriteTest để xem kết quả. Đó là nơi mà khoa học trong khoa học máy tôi mờ sprite để sử dụng tốt trong Chương 18, "Tham gia Trong chiến đấu với NPC", | 220 Chapter 11 Core Technique User Input Using DirectInput to Program a Joystick DirectInput dramatically simplifies joystick programming making it relatively easy to support a wide variety of joysticks with a single code base. The key to programming a joystick with DirectInput lies with two objects called DirectInputDevice8 and DirectlnputEnum-Devices8 as well as a structure called DIDEVCAPS. These three components provide the functionality to write a joystick handler Dim diDev As DirectInputDevice8 Dim diDevEnum As DirectInputEnumDevices8 Dim joyCaps As DIDEVCAPS Reading the List of Game Controllers The first thing you need to do is retrieve a list of available game controllers that are attached to the computer with a DirectInput function called GetDIDevices enumerate the game controllers Set diDevEnum DI8DEVCLASS_GAMECTRL _ DIEDFL_ATTACHEDONLY You can then use the diDevEnum variable to see if a joystick is available If 0 Then MsgBox No joystick could be found End If Creating the Joystick Device Object Once you have determined that a joystick is available the next step is to create the joystick object which is a DirectInputDevice8 object. While DirectInput supports multiple joysticks I show you how to work with the primary joystick attached to the computer because that is all you are likely to need. Here is the code to create the joystick object create the joystick object Set diDev 1 .GetGuidInstance DIFORMAT_JOYSTICK DISCL_BACKGROUND Or _ DISCL_NONEXCLUSIVE The Callback Procedure The next step to writing a joystick handler is to set up the event handler and the callback procedure. The event handler is actually returned by the primary DirectX object rather than the DirectInput object. Any VB program that needs to provide joystick support Programming the Joystick 221 through DirectInput must implement the DirectX event object at the top

TỪ KHÓA LIÊN QUAN