0

我正在制作一个简单的过程,它将创建一个颜色变化的螺旋,这样我就可以测试一系列变量并学习一些 C#。但是,虽然我在代码中找不到问题,但当我调试它时,我返回一个空白的蓝屏。任何人都可以找到问题所在。以下是包含球点所需变量的所有代码:

    Vector2 Tripos;
    List<Color> Tricol;
    List<Vector2> datatripos;
    List<int> count;
    Color currentcol;
    float Tri_angle;
    float Triscale;
    int Tri_speed;
    int screenwidth;
    int screenheight;
    int addtocount;
    Texture2D Ball;
    int colourchangespeed;

 protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.

        Tripos = new Vector2(screenwidth / 2, screenheight / 2);
        Triscale = 1;
        Tri_angle = 1;
        Tri_speed = 1;
        colourchangespeed = 1;
        Ball = Content.Load<Texture2D>("ball");
        currentcol = new Color(0, 0, 0);
        addtocount = 0;
        datatripos = new List<Vector2>();
        Tricol = new List<Color>();
    }

这由更新方法调用:

        private void Posgen()
    {

        Tripos.X += (float)Math.Sin(MathHelper.ToRadians(Tri_angle))*Tri_speed;
        Tripos.Y += (float)Math.Cos(MathHelper.ToRadians(Tri_angle))*Tri_speed;
        Tri_angle++;
    }
    private void colchanger()
    {
        currentcol.R += (byte)colourchangespeed;
        if (currentcol.R == 255)
        {
            currentcol.R = 0;
            currentcol.G += (byte)colourchangespeed;
        }
        if (currentcol.G == 255)
        {
            currentcol.G = 0;
            currentcol.B += (byte)colourchangespeed;
        }
        if (currentcol.B == 255)
        {
            currentcol.B = 0;
        }
    }
    private void dataadd()
    {
        addtocount++;
        Tricol.Add(currentcol);
        datatripos.Add(Tripos);
        count.Add(addtocount);
    }

由draw方法调用:

    private void drawtri()
    {
        foreach (Vector2 data in datatripos)
        {
            spriteBatch.Draw(Ball, data, null, currentcol, 0, new Vector2(5, 5), Triscale, SpriteEffects.None, 0);
        }
    }

如果您想要完整的代码,请提前询问。有些变量我不使用,但我打算稍后使用,所以忽略这些。

提前致谢。

你的莫娜。

4

1 回答 1

0

检查您是否正在呼叫dataadd()

作为预防措施,colourchangespeed应该将其声明为一个字节而不是一个,int因为无论如何您只是转换为一个字节。检查颜色值时,应比较当前值,>= 255因为colourchangespeed它不是 1。

写好问题的提示:删除所有不相关的内容。一切。

于 2013-06-21T09:29:22.007 回答