Windows phone 7 避免在屏幕转换期间多次按下按钮XNA WP7
我有两节课。屏幕和按钮 我的游戏的所有不同屏幕都继承了Screen类 然后将按钮添加到screen类中,并在screen的更新函数中更新(按钮的更新函数) 这是我的按钮更新的代码Windows phone 7 避免在屏幕转换期间多次按下按钮XNA WP7,windows-phone-7,Windows Phone 7,我有两节课。屏幕和按钮 我的游戏的所有不同屏幕都继承了Screen类 然后将按钮添加到screen类中,并在screen的更新函数中更新(按钮的更新函数) 这是我的按钮更新的代码 foreach (TouchLocation touch in TouchPanel.GetState()) { if (touch.State == TouchLocationState.Pressed) { Point
foreach (TouchLocation touch in TouchPanel.GetState())
{
if (touch.State == TouchLocationState.Pressed)
{
Point point = new Point((int)touch.Position.X, (int)touch.Position.Y);
if (rectangle.Contains(point))
{
pressed = true;
color = Color.Red;
}
else
{
pressed = false;
color = Color.White;
}
break;
}
}
现在问题来了
就像前面提到的。我正在调用当前屏幕更新方法中所有按钮的更新方法。替换
TouchLocationState。用TouchLocationState按下。移动。它对我有用
foreach (TouchLocation touch in touches)
{
if (touch.State == TouchLocationState.Moved)
{
if (leftRectangle.Contains((int)touch.Position.X, (int)touch.Position.Y))
{
spriteMove.X -= 5;
}
if (upRectangle.Contains((int)touch.Position.X, (int)touch.Position.Y))
{
spriteMove.Y -= 5;
}
if (rightRectangle.Contains((int)touch.Position.X, (int)touch.Position.Y))
{
spriteMove.X += 5;
}
if (downRectangle.Contains((int)touch.Position.X, (int)touch.Position.Y))
{
spriteMove.Y += 5;
}
}
}
将TouchLocationState.替换为TouchLocationState.Moved
。它对我有用
foreach (TouchLocation touch in touches)
{
if (touch.State == TouchLocationState.Moved)
{
if (leftRectangle.Contains((int)touch.Position.X, (int)touch.Position.Y))
{
spriteMove.X -= 5;
}
if (upRectangle.Contains((int)touch.Position.X, (int)touch.Position.Y))
{
spriteMove.Y -= 5;
}
if (rightRectangle.Contains((int)touch.Position.X, (int)touch.Position.Y))
{
spriteMove.X += 5;
}
if (downRectangle.Contains((int)touch.Position.X, (int)touch.Position.Y))
{
spriteMove.Y += 5;
}
}
}
可能您可以尝试检测TouchLocationState.Released
而不是TouchLocationState.Pressed
?可能您可以尝试检测TouchLocationState.Released
而不是TouchLocationState.Pressed
?