2012-11-26 31 views
1

我创建了一个基本的DrawableGameComponent并实现了UpdateDraw函数。我更新的方法是这样的:DrawableGameComponent不响应我的水龙头

 public override void Update(GameTime gameTime) 
     { 
      if (this.state != ComponentState.Hidden) 
      { 
       if (this.state == ComponentState.Visible) 
       { 
        while (TouchPanel.IsGestureAvailable) 
        { 
         GestureSample gesture = TouchPanel.ReadGesture(); 

         if (gesture.GestureType == GestureType.Tap) 
         { 
          Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y); 

          // TODO: handle input here! 
          this.state = ComponentState.Hidden; // test 
         } 
        } 
       } 
      } 

      base.Update(gameTime); 
     } 

而且我已经启用了在构造以下手势:

TouchPanel.EnabledGestures = GestureType.Tap | GestureType.VerticalDrag; 

这里的问题是,它并没有对如果测试反应过来的时候我检查自来水。有什么我需要做的DrawableGameComponent?

+0

您是否尝试删除组件可见性检查?假设你没有从其他地方读取它们,你的手势相关的代码看起来很好。 –

+0

@Layoric如果我在它命中的while循环上设置断点。 – Jason94

+0

是'TouchPanel.ReadGesture();'你的代码中的任何其他地方?另一个组件也正在处理? –

回答

1

看起来你的手势正在读取其他地方的代码,当你提供的代码检查TouchPanel.IsGestureAvailable这是错误的,因为它们都被读取。

解决这个问题的一个常见方法是创建一个InputState类,它包装您可能拥有的不同屏幕的所有输入代码。这种模式(以及其他一些好的模式)可以在microsoft在其教育部分提供的GameState Management Sample中找到。这个样本是任何项目的一个非常好的起点,因为它会照顾屏幕管理,输入等。

希望有所帮助。