c#, xna, wp7 touch screen not working
I am making a wp7 application and my touch screen doesnt seem to work. The code that i have wrote is below
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);
}
The problem can be that you trying to draw something in Update method. Draw method is for drawing. So in your case you draw something in Update method next you draw background in Draw method so you overried your text.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// overriding here
... draw background
// *draw your text should be here
base.Draw(gameTime);
}
So the solution is to move "spriteBatch.DrawString(...);" to Draw method and put it below background in your code or add depth parameter to draw methods.
looking at your code now, nothing seems wrong, but have you tried stepping through it? I see that tapping or double tapping do the same thing, but maybe something is being hung up.
The first thing that I thought of though, is your XAML. Do you have a control or something over top everything else? This could be catching you gestures.
If neither works, could you post more information?
精彩评论