Reputation: 13620
I've created a basic DrawableGameComponent
and implemented Update
and Draw
function. My Update method looks like this:
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);
}
And I have enabled the following gestures in the constructor:
TouchPanel.EnabledGestures = GestureType.Tap | GestureType.VerticalDrag;
The problem here is that it does not react on the if test when I check for Tap. Is there something I need to do with the DrawableGameComponent?
Upvotes: 1
Views: 91
Reputation: 2322
It seems that your gestures are being read else where in the code and when your provided code checks for TouchPanel.IsGestureAvailable
it is false as they have all been read.
A common way around this is to create an InputState class that wraps all your input code for the different screens you might have. This pattern (and a few other good ones) can be found in the GameState Management Sample that microsoft provide in their educational section. This sample is a really good starting point for any project as it takes care of screen management, input etc.
Hope that helps.
Upvotes: 1