【发布时间】:2010-12-16 04:57:08
【问题描述】:
我目前正在开发一款游戏,其中我们需要结合使用 DrawUserIndexedPrimitives 和普通 spriteBatch.Draw。没有组合,因为我们同时使用它们,但我们首先必须使用 spriteBatch 绘制一些 2d 精灵,然后我们禁用 spriteBatch 以启用 basicEffect 并绘制图元,最后再次启用 spriteBatch。下面的代码显示了发生问题的代码部分。
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, cam.get_transformation(GraphicsDevice));
levelController.Draw(spriteBatch);
if (gameReady)
{
foreach (GameObject.GameObject go in gameObjects)
{
go.Draw(spriteBatch);
}
spriteBatch.End();
foreach (GameObject.GameObject go in gameObjects)
{
if (go is GameObject.Enemy.Enemy)
{
GameObject.Enemy.Enemy enemy = (GameObject.Enemy.Enemy)go;
basicEffect = new BasicEffect(graphics.GraphicsDevice);
basicEffect.VertexColorEnabled = true;
basicEffect.CurrentTechnique.Passes[0].Apply();
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, enemy.GetCollisionTriangle.Triangle, 0, 3, enemy.GetCollisionTriangle.Indices, 0, 1);
}
}
}
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, cam.get_transformation(GraphicsDevice));
如果下面的代码被引用,则延迟停止。
basicEffect = new BasicEffect(graphics.GraphicsDevice);
basicEffect.VertexColorEnabled = true;
basicEffect.CurrentTechnique.Passes[0].Apply();
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, enemy.GetCollisionTriangle.Triangle, 0, 3, enemy.GetCollisionTriangle.Indices, 0, 1)
真的是我们不能同时使用 spriteBatch 和 basicEffect 而不会使游戏延迟很多吗?它已经在 3 台不同的计算机上进行了测试,从非常旧的笔记本电脑到全新的游戏玩家 PC。 由于出现延迟,游戏无法玩。
【问题讨论】: