Input 检测拖放和检测长压(XNA或as3)
我试图实现一个对象的拖放行为,我需要在触摸被按下时进行注册,移动一点后,它应该开始拖动 不幸的是,我使用的是一个用C#实现的定制框架,它类似于XNA 在XNA上你会怎么做Input 检测拖放和检测长压(XNA或as3),input,xna,touch,mouse,drag,Input,Xna,Touch,Mouse,Drag,我试图实现一个对象的拖放行为,我需要在触摸被按下时进行注册,移动一点后,它应该开始拖动 不幸的是,我使用的是一个用C#实现的定制框架,它类似于XNA 在XNA上你会怎么做 (适用于android平板电脑)。显然,这个例子应该进行重构,以使用输入服务和更好地处理触动/触动概念,但答案的核心仍然是一样的: // I don't remember the exact property names, but you probably understand what I mean public overr
(适用于android平板电脑)。显然,这个例子应该进行重构,以使用输入服务和更好地处理触动/触动概念,但答案的核心仍然是一样的:
// I don't remember the exact property names, but you probably understand what I mean
public override void Update(GameTime time)
{
var currentState = TouchPanel.GetState();
var gestures = currentState.TouchGestures;
var oldGests = this.oldState.TouchGestures;
if (oldGests.Count == 0 && gestures.Count == 1 && gestures[0].State == Pressed)
{
// Went from Released to Pressed
this.touchPressed = true;
}
else
{
// Not the frame it went to Pressed
this.touchPressed = false;
}
if (oldGests.Count == 1 && gestures.Count == 1 && oldGests[0].State == Pressed && gestures[0].State == Pressed)
{
// Touch is down, and has for more than 1 frame (aka. the user is dragging)
this.touchDown = true;
}
else
{
this.touchDown = false;
}
if (oldGests.Count == 1 && oldGests[0].State == Pressed && gestures.Count == 0)
{
// Went from Released to Pressed
this.touchReleased = true;
}
else
{
// Not the frame it went to Pressed
this.touchReleased = false;
}
this.oldState = currentState;
}
你可能需要稍微摆弄一下“如果”,因为我不记得在你松开手指后的第一帧手势是否下降到0,或者它是否仍然显示一个称为“释放”的手势。测试一下,你就会得到你的答案
现在,您可以在代码的其他地方使用“this.touchtown”来确定对象是否应该移动