0

我将每个对象的绘图保存在一个单独的类中,然后在主绘图类中调用它。无论如何,我需要把这个循环弄好,因为我会在很多地方建模。

它会第一次为我绘制,但之后 xCoord 似乎没有为我移动,否则循环还有其他问题。没有语法错误之类的,程序运行,只是不是我想要的!

任何帮助将非常感激...

    /// <summary>
    /// Draws the bottom platform (ground)
    /// </summary>
    public void DrawBottomPlatform()
    {

        int xCoord = 0;
        int yCoord = (screenHeight / 10) * 9;
        int width = screenWidth / 20;
        int height = screenHeight / 20;
        Rectangle bottomRectangle = new Rectangle(xCoord, yCoord, width, height);

        int i = 0;
        while (i <= 5)
        {
            spriteBatch.Draw(grassTexture, bottomRectangle, Color.White);
            xCoord += bottomRectangle.Width;
            i += 1;
        }


    }
4

1 回答 1

4

您永远不会使用您的 updated xCoord,一旦循环开始,该值就会被忽略。在每次迭代时移动矩形而不是更新xCoord

    int i = 0;
    while (i <= 5)
    {
        spriteBatch.Draw(grassTexture, bottomRectangle, Color.White);
        bottomRectangle.X += bottomRectangle.Width;
        i += 1;
    }
于 2013-09-27T20:31:16.270 回答