1

在我重写了我的 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);
        }
    }
4

0 回答 0