在XNA中绘制切片时FPS滞后

时间:2014-02-12 20:29:17

标签: xna-4.0 lag frame-rate

我正在xna 4.0中开发自己的基于平铺的游戏,并且在屏幕上绘制图块时会遇到大的fps滞后。 我已经阅读了很多关于提高性能的知识,我已经知道了:

我将瓷砖存储在一个简单的字典中

private Dictionary<Vector2, IBlock> WorldBlocks;
private Vector2 ExactBlockPosition;
private IBlock ExistingBlock;

    public void Draw(SpriteBatch SpriteBatch, Vector2 ScreenStart, Vector2 ScreenEnd)
    {
        // Run over all the blocks in the screen
        for (this.ExactBlockPosition.X = this.GetCurrentBlockXPosition(ScreenStart.X);
             this.ExactBlockPosition.X < ScreenEnd.X;
             this.ExactBlockPosition.X += Global.BLOCK_WIDTH)
        {
            for (this.ExactBlockPosition.Y = this.GetCurrentBlockYPosition(ScreenStart.Y);
                 this.ExactBlockPosition.Y < ScreenEnd.Y;
                 this.ExactBlockPosition.Y += Global.BLOCK_HEIGHT)
            {
                // Check if there is a block in the exact block location
                if (this.WorldBlocks.TryGetValue(this.ExactBlockPosition, out this.ExistingBlock))
                {
                    // Draw the block on the screen
                    this.ExistingBlock.Draw(SpriteBatch);
                }
            }
        }
    }

    private int GetCurrentBlockXPosition(float X)
    {
        return (int)(X - X % Global.BLOCK_WIDTH);
    }

    private int GetCurrentBlockYPosition(float Y)
    {
        return (int)(Y - Y % Global.BLOCK_WIDTH);
    }

简而言之,此代码仅绘制屏幕上的块。 但是当屏幕上有很多瓷砖时,我的fps仍会下降到31。 瓷砖宽度和高度为20像素。 有什么建议为什么我的fps下降?

0 个答案:

没有答案
相关问题