I've got this array:
| int myType = 0; |
| int[,] pos = new int[3, 1]; |
| int numb = 0; |
| int formation = 1; |
| switch (formation) |
| { |
| case 1: |
| myType = 1; |
| pos[0, 0] = 16; |
| pos[0, 1] = -48; |
| pos[1, 0] = 64; |
| pos[1, 1] = -32; |
| pos[2, 0] = 144; |
| pos[2, 1] = -32; |
| pos[3, 0] = 144; |
| pos[3, 1] = -48; |
| numb = 5; |
| break; |
| |
| case 2: |
| myType = 1; |
| numb = 4; |
| break; |
| |
| case 3: |
| myType = 1; |
| numb = 5; |
| break; |
| } |
| |
| for (int i = 0; i < numb; i++) |
| { |
| GameObject ship = new GameObject(Content.Load<Texture2D>("en" + myType.ToString())); |
| ship.X = pos[i, 0]; |
| ship.Y = pos[i, 1]; |
| ships.Add(ship); |
| } |
This code (inside a void function) gets run each time I press space.
When I press space my game freezes and Visual Studio goes to the line: pos[0, 1] = -48; and highlights it in yellow, and throws this error:
"Index was outside the bounds of the array."
???