C#对游戏手柄的编程开发-API篇(2)
2009-03-29 08:22:06 来源:WEB开发网这时我们就要用到以下的API函数。
/// <summary>
/// 获取操纵杆位置和按钮状态
/// </summary>
/// <param name="uJoyID"></param>
/// <param name="pji"></param>
/// <returns></returns>
[DllImport("winmm.dll")]
public static extern int joyGetPos(int uJoyID, ref JOYINFO pji);
/// <summary>
/// 获取操纵杆位置和按钮状态
/// </summary>
/// <param name="uJoyID"></param>
/// <param name="pji"></param>
/// <returns></returns>
[DllImport("winmm.dll")]
public static extern int joyGetPosEx(int uJoyID, ref JOYINFOEX pji);
上面的两个API函数,我们可以从中任选一个,但joyGetPos函数只能取得1,2,3,4号四个按钮的状态。所以建议不用,下面只重讲解joyGetPosEx函数!
JOYINFO 与 JOYINFOEX 是属于结构体,它们的定义如下:
#region 游戏手柄的位置与按钮状态
/// <summary>
/// 游戏手柄的位置与按钮状态
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct JOYINFO
{
public int wXpos;
public int wYpos;
public int wZpos;
public int wButtons;
}
/// <summary>
/// 游戏手柄的位置与按钮状态
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct JOYINFOEX
{
/// <summary>
/// Size, in bytes, of this structure.
/// </summary>
public int dwSize;
/// <summary>
/// Flags indicating the valid information returned in this structure. Members that do not contain valid information are set to zero.
/// </summary>
public int dwFlags;
/// <summary>
/// Current X-coordinate.
/// </summary>
public int dwXpos;
/// <summary>
/// Current Y-coordinate.
/// </summary>
public int dwYpos;
/// <summary>
/// Current Z-coordinate.
/// </summary>
public int dwZpos;
/// <summary>
/// Current position of the rudder or fourth joystick axis.
/// </summary>
public int dwRpos;
/// <summary>
/// Current fifth axis position.
/// </summary>
public int dwUpos;
/// <summary>
/// Current sixth axis position.
/// </summary>
public int dwVpos;
/// <summary>
/// Current state of the 32 joystick buttons. The value of this member can be set to any combination of JOY_BUTTONn flags, where n is a value in the range of 1 through 32 corresponding to the button that is pressed.
/// </summary>
public int dwButtons;
/// <summary>
/// Current button number that is pressed.
/// </summary>
public int dwButtonNumber;
/// <summary>
/// Current position of the point-of-view control. Values for this member are in the range 0 through 35,900. These values represent the angle, in degrees, of each view multiplied by 100.
/// </summary>
public int dwPOV;
/// <summary>
/// Reserved; do not use.
/// </summary>
public int dwReserved1;
/// <summary>
/// Reserved; do not use.
/// </summary>
public int dwReserved2;
}
#endregion
- ››编程实例 一个简单的智能感知效果
- ››游戏定位成牵引Android发展的火车头
- ››游戏场景烘焙贴图制作
- ››游戏植物大战僵尸 iPhone 版9天销售额超100万美元...
- ››游戏开发包 iPhone cocos2d 初体验
- ››游戏三维怪物施法特效教程
- ››游戏人生Silverlight(2) - 趣味钢琴[Silverlight ...
- ››游戏人生Silverlight(3) - 打苍蝇[Silverlight 2....
- ››游戏人生Silverlight(4) - 连连看[Silverlight 2....
- ››游戏人生Silverlight(5) - 星际竞技场[Silverligh...
- ››游戏《封神榜》人物纣王3DMAX制作全过程
- ››编程快捷删除文档中多余的空行
更多精彩
赞助商链接