I am trying to create 2D vector2 arrays in XNA,C#.
I used the following statement:
Vector2[][] SpritePosition=new Vector2[4][];
Then I used the following for loop to initialize them:
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
}
}
However, when I used the for loop, as stated above, it gave me an error, actually two:
- Int is a field and used as a type.
- ‘for’ is an invalid token in class, struct or interface member declaration.
Can anyone tell why am I facing such a problem?
EDIT: This is the code:
public class Game1 : Microsoft.Xna.Framework.Game
{
int i=new int();
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D texture;
//Vector2[,] SpritePosition = new Vector2[4,4];
Vector2[,] SpriteSpeed = new Vector2[4,4];
for(i=0;i<4;i++)
{
}
}
Seems you need to read up on some C# Tutorials
You are going to need a function for that as so,
You can call it from your initialize method, using
LoadArray()}
Also, You dont need int
i = new Int()for basic stuff like strings, ints, etc you dont need the new Whatever() partJust do
for(int i=0;i<4;i++){
}