Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#,xna,wp7触摸屏不工作_C#_Windows Phone 7_Touchscreen_Xna 4.0 - Fatal编程技术网

c#,xna,wp7触摸屏不工作

c#,xna,wp7触摸屏不工作,c#,windows-phone-7,touchscreen,xna-4.0,C#,Windows Phone 7,Touchscreen,Xna 4.0,我正在制作一个wp7应用程序,但我的触摸屏似乎无法正常工作。我写的代码如下 protected override void Update(GameTime gameTime) { TouchCollection touches = TouchPanel.GetState(); if (touches.Count > 0 && touches[0].State == TouchLocationState.Pressed) { Sprit

我正在制作一个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);
}
受保护覆盖无效更新(游戏时间游戏时间)
{
TouchCollection touchs=TouchPanel.GetState();
如果(touchs.Count>0&&touchs[0].State==TouchLocationState.Pressed)
{
SpriteFont=Content.Load(“字体”);
点接触点=新点((int)接触[0]。位置.X,(int)接触[0]。位置.Y);
spriteBatch.Begin();
spriteBatch.DrawString(字体“hello”,新矢量2(touchPoint.X,touchPoint.Y),颜色为白色);
spriteBatch.End();
while(TouchPanel.IsGestureAvailable)
{
GestureSample手势=TouchPanel.Read手势();
开关(手势.手势类型)
{
案例手势类型。轻按:
case GestureType.DoubleTap:
spriteBatch.Begin();
spriteBatch.DrawString(字体,“”,新矢量2(touchPoint.X,touchPoint.Y),Color.White);
spriteBatch.End();
打破
}
}
}
更新(游戏时间);
}

现在查看您的代码,似乎没有什么问题,但您是否尝试过单步执行?我看到敲击或双重敲击做同样的事情,但可能有什么东西被挂断了

我想到的第一件事是你的XAML。你能控制一切吗?这可能会抓住你的手势


如果两者都不起作用,您能发布更多信息吗?

问题可能是您试图在更新方法中绘制一些东西。 绘制方法用于绘制。 所以,在你们的例子中,你们在更新方法中画一些东西,然后在绘制方法中画背景,这样你们就高估了你们的文本

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方法并将其放在下面
在代码中添加背景或添加深度参数以绘制方法。

这是一个XNA问题,不是Silverlight,因此不会出现任何Xaml问题。这怎么不起作用?有接触过吗?第一个的状态是什么?是否抛出任何错误?