我从XNA例子中写过Shooter Game。这个游戏支持触摸,键盘和游戏手柄输入。
如果我在使用键盘,触摸屏和Xbox One控制器的Windows 10桌面上运行此游戏,我可以使用所有输入法。
你有什么建议: a)是否有能力控制各种方式? b)在游戏菜单的标签设置中添加选择一种控制方法的能力:触摸/键盘/游戏手柄?
如何将游戏编程为活动只是用户在游戏设置中选择的一种控制模式?
我的游戏中的以下代码在方法中执行:覆盖类Game1中的void Update(GameTime GameTime):游戏
触摸输入:
while (TouchPanel.IsGestureAvailable)
{
GestureSample gesture = TouchPanel.ReadGesture();
if (gesture.GestureType == GestureType.FreeDrag)
{
player.Position += gesture.Delta;
}
}
键盘和游戏手柄
if (currentKeyboardState.IsKeyDown(Keys.Left)|| currentGamePadState.DPad.Left==ButtonState.Pressed)
{
player.Position.X -= playerMoveSpeed;
}
if (currentKeyboardState.IsKeyDown(Keys.Right) || currentGamePadState.DPad.Right == ButtonState.Pressed)
{
player.Position.X += playerMoveSpeed;
}
if (currentKeyboardState.IsKeyDown(Keys.Up)|| currentGamePadState.DPad.Up == ButtonState.Pressed)
{
player.Position.Y -= playerMoveSpeed;
}
if (currentKeyboardState.IsKeyDown(Keys.Down) || currentGamePadState.DPad.Down==ButtonState.Pressed)
{
player.Position.Y += playerMoveSpeed;
}