手势 FreeDrag 性能
我有一个简单的问题,我正在尝试为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
固定的!
这太愚蠢了..
可能会发生我们在抽奖之前同时进行多次触摸的情况,所以我们必须放一个WHILE而不是IF,
然后它就会
像魅力一样工作了!
我希望这对可能遇到同样问题的人有所帮助
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
then it will be
now it works like a charm!!!
I hope that this will be helpful for people who may have the same problem