【发布时间】:2013-12-11 15:33:02
【问题描述】:
我对 BoundingBox 和制作中的东西有奇怪的问题。 For 循环无法正常工作并导致不改变变量的问题。
for (int i = 0; i < thing.Length; i++)
{
for (int j = 0; j < thing.Length; j++)
{
if (thing[i].bb.Intersects(thing[j].bb) && i != j)
{
thing[i].spriteSpeed *= -1;
thing[j].spriteSpeed *= -1;
soundEffect.Play(0.2f, -1f, 0f);
}
}
}
但是如果我将 j 变量更改为静态数字,比如零,代码就可以正常工作。
for (int i = 0; i < thing.Length; i++)
{
for (int j = 0; j < thing.Length; j++)
{
if (thing[i].bb.Intersects(thing[0].bb) && i != 0)
{
thing[i].spriteSpeed *= -1;
thing[0].spriteSpeed *= -1;
soundEffect.Play(0.2f, -1f, 0f);
}
}
}
附: Thing 是一个看起来像这样的结构:
struct Thing
{
public Texture2D myTexture;
public Vector2 spritePosition;
public Vector2 spriteSpeed;
public BoundingBox bb;
public Vector3 start, end;
}
【问题讨论】:
-
Tnx 科里。它对我来说很好。
标签: c# visual-studio-2010 xna