MonoGame.Framework.dll中发生未处理的“System.ArgumentNullException”类型异常

时间:2014-07-10 09:15:05

标签: c# monogame argumentnullexception

我正在尝试使用MonoGame创建一个简单的游戏。

我目前面临的问题是,有时候(比如有一半的时间)我的代码运行没有问题。但是有时候它会把我这个例外:

MonoGame.Framework.dll中出现未处理的“System.ArgumentNullException”类型异常

附加信息:值不能为空。

所以我的问题是如何处理这类问题,因为它不会一直发生? 我试过清理我的解决方案。但有时它在我清理解决方案后仍然会直接发生。

堆栈跟踪在我的Draw()中; spriteBatch.Draw();

行的方法
public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Begin();
        spriteBatch.Draw(InitialTexture, InitialPlatformPosition, InitialPlatformSprite, Color.White);

        for (int x = 0; x <= 4; x++)
        {
            spriteBatch.Draw(TextureArray1[x], PlatformPosition1 + new Vector2(platformWidth * x, 0), PlatformSprite, Color.White);
            spriteBatch.Draw(TextureArray2[x], PlatformPosition2 + new Vector2(platformWidth * x, 0), PlatformSprite, Color.White);
        }

        spriteBatch.End();
    }

有时它会在第二行达到第二行时触及第一行。

我正在尝试创建一个无限运行平台,它可以随机选择type1或type2。这是Update()中的代码;在我的Draw()之上的方法;方法,以备不时之需。

public void Update(GameTime gameTime)
    {
        int speed = -(int)(gameTime.ElapsedGameTime.TotalSeconds * velocity);
        InitialPlatformPosition += new Vector2(speed, 0);
        PlatformPosition1 += new Vector2(speed, 0);
        PlatformPosition2 += new Vector2(speed, 0);




        // Create First Array of Random Texture
        if (InitialPlatformPosition.X < -datum1)
        {
            datum1X++;
            datum1 = datum1X * 1920;
            for (int x = 0; x <= 4; x++)
            {
                random.Next(2);
                if (random.Next(2) == 0)
                    PlatformChoice1 = Texture;
                else if (random.Next(2) == 1)
                    PlatformChoice1 = TextureFlipped;
                // insert random platform into an array of 10 Texture
                TextureArray1[x] = PlatformChoice1;
            }
            if (datum1X != 1)
            {
                PlatformPosition1 += new Vector2(1920, 0);
            }
        }

        // Create Second Array of Random Texture
        if (InitialPlatformPosition.X < datum2)
        {
            datum2X++;
            datum2 = -(1920 - datum2);
            if (datum2X == 1 || datum2X >= 3)
            {
                for (int x = 0; x <= 4; x++)
                {
                    random.Next(2);
                    if (random.Next(2) == 0)
                        PlatformChoice2 = Texture;
                    else if (random.Next(2) == 1)
                        PlatformChoice2 = TextureFlipped;
                    // insert random platform into an array of 10 Texture
                    TextureArray2[x] = PlatformChoice2;
                }
            }
            if (datum2X >= 3)
            {
                PlatformPosition2 += new Vector2(1920, 0);
            }
        }
    }

请尝试用更简单的术语向我解释,因为我对编程世界很新,特别是对C#和MonoGame。

0 个答案:

没有答案
相关问题