2011-05-02 56 views
0

我正在制作wp7应用程序,而我的触摸屏似乎无法工作。我写的代码是c#,xna,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); 
} 
+0

这是怎么回事?有没有任何接触?第一个的状态是什么?是否有错误被抛出? – 2011-05-03 08:31:17

回答

0

现在看看你的代码,没有什么看起来不对,但你有没有尝试过它?我发现敲击或双敲击可以做同样的事情,但也许有些事情正在被挂断。

我想到的第一件事就是你的XAML。你有一个控制或其他所有东西吗?这可能会抓住你的手势。

如果两者都不起作用,您是否可以发布更多信息?

+0

这是一个XNA问题,而不是Silverlight,所以不会有任何XAML – 2011-05-03 08:29:42

1

问题可能是您尝试在Update方法中绘制某些东西。 绘制方法是绘制。 因此,在您的情况下,您在Update方法中绘制一些东西,然后在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(...);”绘制方法并将其放在代码背景下面或添加深度参数以绘制方法。