Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XNA-重复纹理x次数_C#_Xna_Sprite - Fatal编程技术网

C# XNA-重复纹理x次数

C# XNA-重复纹理x次数,c#,xna,sprite,C#,Xna,Sprite,我有一个基本的砖块纹理,我想在X轴上重复一定次数。除了(可能)反复使用spriteBatch.Draw(…)绘制数百个相同的纹理外,还有没有像spriteBatch.Draw(brick,vector\u array[],color)这样更简单的方法呢将是我所有的向量点,以便反复绘制纹理 与这个想法无关,我下一个最好的想法是做如下事情: for (int i = 0; i <= 16; i += 1) { spriteBatch.Dr

我有一个基本的砖块纹理,我想在X轴上重复一定次数。除了(可能)反复使用
spriteBatch.Draw(…)
绘制数百个相同的纹理外,还有没有像
spriteBatch.Draw(brick,vector\u array[],color)
这样更简单的方法呢将是我所有的向量点,以便反复绘制纹理

与这个想法无关,我下一个最好的想法是做如下事情:

for (int i = 0; i <= 16; i += 1)
            {
                spriteBatch.Draw(brick, brickXY, Color.White);
                brickXY.X += 32;
            }
    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        brick = Content.Load<Texture2D>("Whatever texture you want here");
        (int a = 0; a < brickXY.Length - 1; a++)
        {
            brickXY[a].X += (32 * a);
        }
    }

对于(int i=0;i请尝试在其他位置设置砖块XY。
您正在单独设置BrickXY,但它是一个数组,因此需要
砖块XY[int]
尝试以下方法:

for (int i = 0; i <= 16; i += 1)
            {
                spriteBatch.Draw(brick, brickXY, Color.White);
                brickXY.X += 32;
            }
    protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        brick = Content.Load<Texture2D>("Whatever texture you want here");
        (int a = 0; a < brickXY.Length - 1; a++)
        {
            brickXY[a].X += (32 * a);
        }
    }
protected override void LoadContent()
{
spriteBatch=新spriteBatch(图形设备);
brick=Content.Load(“此处需要的任何纹理”);
(int a=0;a
设置完所有值后,绘制它们,否则砖块将开始移动

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        spriteBatch.Begin();
        for (int i = 0; i <= brickXY.Length - 1; i++)
        {
            spriteBatch.Draw(brick, brickXY[i], Color.White);
        }
        spriteBatch.End();
        base.Draw(gameTime);
    }
protected override void Draw(游戏时间游戏时间)
{
图形设备。清晰(颜色:矢车菊蓝);
spriteBatch.Begin();

for(int i=0;谢谢!这完全奏效了。我真的不明白为什么我的for循环方法不起作用,但这很好。实际上,您可以在不需要多次绘制调用的情况下执行此操作。请参阅。