/// <summary> /// Re-randomizes the stars drawn in the far area /// </summary> void RefreshBackground(int numStars) { if (numStars > Stars.Length / 4) { int PreviousStarNumber = Stars.Length / 4; Array.Resize <VertexPositionColorTexture>(ref Stars, numStars * 4); Array.Resize <int>(ref StarIndex, numStars * 6); for (int i = PreviousStarNumber; i < numStars; i++) { Vector3 position = Manager.GetRandomNormal() * (0.6f + 0.4f * (float)MyGame.random.NextDouble()); Vector2 texture = new Vector2(0.1f * MyGame.random.Next(10), 0.1f * MyGame.random.Next(10)); Stars[i * 4] = new VertexPositionColorTexture( position , Manager.GetRandomColor(true) , texture); Stars[i * 4 + 1] = new VertexPositionColorTexture( position , Manager.GetRandomColor(true) , texture + Vector2.UnitX * 0.099f); Stars[i * 4 + 2] = new VertexPositionColorTexture( position , Manager.GetRandomColor(true) , texture + Vector2.UnitY * 0.099f); Stars[i * 4 + 3] = new VertexPositionColorTexture( position , Manager.GetRandomColor(true) , texture + Vector2.One * 0.099f); StarIndex[i * 6] = i * 4; StarIndex[i * 6 + 1] = i * 4 + 1; StarIndex[i * 6 + 2] = i * 4 + 3; StarIndex[i * 6 + 3] = i * 4; StarIndex[i * 6 + 4] = i * 4 + 3; StarIndex[i * 6 + 5] = i * 4 + 2; } } else if (numStars < Stars.Length / 4) { Array.Resize <int>(ref StarIndex, numStars * 6); //Randomize the order of stars a bit int numChanges = Stars.Length / 4 - numStars; for (int i = 0; i < numChanges; i++) { int OtherIndex = MyGame.random.Next(Stars.Length / 4); VertexPositionColorTexture temp; for (int j = 0; j < 4; j++) { temp = Stars[i * 4 + j]; Stars[i * 4 + j] = Stars[OtherIndex * 4 + j]; Stars[OtherIndex * 4 + j] = temp; } } Array.Resize <VertexPositionColorTexture>(ref Stars, numStars * 4); } }