我正在制作一个简单的过程,它将创建一个变色螺旋,这样我就可以测试一系列变量并学习一些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);
}
}
如果您想要完整的代码提前询问。有些变量我不使用,但我打算稍后使用,所以忽略这些。
提前致谢。
你的莫娜。
答案 0 :(得分:0)
检查您是否正在呼叫dataadd()
。
作为预防措施,colourchangespeed
应该声明为一个字节而不是int
,因为你只是转换为一个字节。在检查颜色值时,如果>= 255
不是1,则应将当前值与colourchangespeed
进行比较。
撰写好问题的提示:删除所有无关的内容。一切。