我重写了我的block.cs类之后修复了我之前的问题,但是,我有一个最后的问题:
我有256个块的列表,每个块有12个三角形和36个顶点。当我使用:
渲染这些块时blocks.ForEach(block => block.Draw(spriteBatch, camera, effect));
它们会渲染,但游戏速度会急剧下降,大约为0.25 FPS。每个块都有不同的纹理。 3072个三角形和9216个顶点是否会导致这个问题?
我的渲染代码:
public void Render(GraphicsDevice graphicsDevice)
{
if (!isConstructed) ConstructBlock();
using (var buffer = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, NUMVERTICES, BufferUsage.WriteOnly))
{
buffer.SetData(vertices);
graphicsDevice.SetVertexBuffer(buffer);
}
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, NUMTRIANGLES);
}
我的魔方的抽奖代码:
public void Draw(SpriteBatch spriteBatch, Camera camera, BasicEffect effect)
{
effect = new BasicEffect(spriteBatch.GraphicsDevice)
{
TextureEnabled = true,
Texture = Texture,
View = camera.View,
Projection = camera.Projection,
World = Matrix.Identity
};
effect.EnableDefaultLighting();
foreach (var pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
Render(spriteBatch.GraphicsDevice);
}
}