Windows phone 7 - c#, xna, wp7触摸屏不工作
本文关键字:wp7 触摸屏 工作 xna Windows phone | 更新日期: 2023-09-27 17:54:31
我正在制作wp7应用程序,我的触摸屏似乎不工作。我写的代码在
下面protected override void Update(GameTime gameTime)
{
TouchCollection touches = TouchPanel.GetState();
if (touches.Count > 0 && touches[0].State == TouchLocationState.Pressed)
{
SpriteFont font = Content.Load<SpriteFont>("Font");
Point touchPoint = new Point((int)touches[0].Position.X, (int)touches[0].Position.Y);
spriteBatch.Begin();
spriteBatch.DrawString(font, "hello ", new Vector2(touchPoint.X, touchPoint.Y), Color.White);
spriteBatch.End();
while (TouchPanel.IsGestureAvailable)
{
GestureSample gesture = TouchPanel.ReadGesture();
switch (gesture.GestureType)
{
case GestureType.Tap:
case GestureType.DoubleTap:
spriteBatch.Begin();
spriteBatch.DrawString(font, " ", new Vector2(touchPoint.X, touchPoint.Y), Color.White);
spriteBatch.End();
break;
}
}
}
base.Update(gameTime);
}
问题可能是你试图在更新方法中绘制一些东西。Draw方法用于绘制。在你的例子中,你在更新方法中绘制一些东西然后在绘制方法中绘制背景你覆盖了你的文本。
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// overriding here
... draw background
// *draw your text should be here
base.Draw(gameTime);
}
所以解决方案是移动"spriteBatch.DrawString(…);"到Draw方法,并把它放在下面在你的代码背景或添加深度参数绘制方法
现在看看你的代码,似乎没有什么问题,但是你试过逐步完成它吗?我看到轻击或双击做同样的事情,但可能有些东西被挂起了。
我首先想到的是XAML。你是否有一种凌驾于其他一切之上的控制力?这可能是捕捉你的手势。
如果两者都不行,你能发布更多的信息吗?