手势 FreeDrag 性能

发布于 2025-01-06 01:36:07 字数 1234 浏览 4 评论 0原文

我有一个简单的问题,我正在尝试为 Windows Phone 制作一款大型游戏,但我仍然有一个重要的瓶颈/问题/性能不佳。

我使用过 mango profiler,但我没有发现任何问题,事实上它只使用了我手机上 10% 的 cpu。

让我告诉你问题所在。

这是我的更新

protected override void Update(GameTime gameTime)
    {
        if (TouchPanel.IsGestureAvailable)
        {
            var gs = TouchPanel.ReadGesture();
            switch (gs.GestureType)
            {
                case GestureType.FreeDrag:
                    Position += gs.Delta;
                    break;
            }
        }
        base.Update(gameTime);
    }

这是我的绘制,其中地图是 20x15 纹理 2D

protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        spriteBatch.Begin();          
        spriteBatch.Draw(map, Position, null, Color.Red, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);
        spriteBatch.End();

        base.Draw(gameTime);
    }

问题是,绘制对于更新来说似乎太慢了,或者有点慢。

例如:

1)我非常缓慢地拖动右侧的屏幕 ->地图纹理正确地在右侧移动

2) 我将屏幕拖动到右侧,然后拖动到左侧,速度相当快 ->地图纹理正确地在右侧移动,但在向左侧移动时有一点滞后,就像它仍在右侧移动一样。

3)我以圆形方式拖动屏幕,在 1 秒内画一个圆 ->好吧,地图需要 3 秒才能循环移动..

我做错了什么?

我应该给你看一个 youtube 视频吗?

非常感谢你!! 卢卡

I have a simple question, I'm trying to make an huge game for Windows Phone, but I still have a important bottleneck/issue/bad performance.

I've used the mango profiler, but I have seen no problem, infact it's using only 10% cpu on my phone.

Let me show you the problem.

This is my Update

protected override void Update(GameTime gameTime)
    {
        if (TouchPanel.IsGestureAvailable)
        {
            var gs = TouchPanel.ReadGesture();
            switch (gs.GestureType)
            {
                case GestureType.FreeDrag:
                    Position += gs.Delta;
                    break;
            }
        }
        base.Update(gameTime);
    }

This is my Draw, where map is a 20x15 Texture2D

protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        spriteBatch.Begin();          
        spriteBatch.Draw(map, Position, null, Color.Red, 0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);
        spriteBatch.End();

        base.Draw(gameTime);
    }

The problem is that seems that the DRAW is TOO slow for the UPDATE, or kinda of.

For Example:

1) I drag the screen on the right, very slowly -> the map texture is correctly moving on the right

2) I drag the screen on the right, then on the left, quite fast -> the map texture is correctly moving on the right, but has a little lag when moving on the left, like it's still moving on the right..

3) I drag the screen circularly making a circle in 1 second -> well, the map needs 3 seconds to make a move circularly..

What I'm doing wrong??

Should I show you a youtube video??

Thanks you very much!!
Luca

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

焚却相思 2025-01-13 01:36:07

固定的!

这太愚蠢了..

可能会发生我们在抽奖之前同时进行多次触摸的情况,所以我们必须放一个WHILE而不是IF,

if (TouchPanel.IsGestureAvailable)

然后它就会

while (TouchPanel.IsGestureAvailable)

像魅力一样工作了!

我希望这对可能遇到同样问题的人有所帮助

FIXED!

this was so stupid..

it may happen that we have multiple touch in the same time before the draw, so we have to put a WHILE instead of IF on

if (TouchPanel.IsGestureAvailable)

then it will be

while (TouchPanel.IsGestureAvailable)

now it works like a charm!!!

I hope that this will be helpful for people who may have the same problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文