切换输入 [英] Toggle an input

查看:127
本文介绍了切换输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SlimDX来使用我的Xbox 360控制器,我想要一种方法,当按下控制器上的按钮时,状态变为打开并保持打开状态,但是当我再次按下它时,它变为关闭状态.有点像拨动开关.但是到目前为止,我还无法做任何事情(真的只是一个初学者).

I am using SlimDX to use my Xbox 360 controller and I would like a way of when pressing a button on the controller the state changes to on and stays on but when I press it again it becomes off. Sort of like a toggle. But I have been unable to do one so far(Just a beginner really).

感谢您的帮助. 托马斯.

Thanks for any help. Thomas.

推荐答案

您可以使用bool确定按钮是打开还是关闭.您还需要知道游戏板的先前状态,因此bool不会一直都在切换,只是因为您不断按下按钮即可.

You may use a bool to determine if the button is toggled on or off. You will also need to know the gamepad's previous state, so the bool won't toggle all the time, just because you keep pressing the button.

bool myCommand = false; // declare the bool
GamePadState oldState; // you need to know the previous state of your gamepad

public void Update()
{
    if (GamePad.GetState().KeyPressed == /*key*/ && oldState.KeyPressed != /*key*/)
        myCommand = !myCommand;
    oldState = GamePad.GetState();
}

请记住,您可能需要使用GamePadGamePadState以外的其他内容,因为这只是伪代码

Keep in mind, that you may need to use something other than GamePad or GamePadState, as this is merely pseudo-code

这篇关于切换输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆