I have an array of objects Letter, and if keyboard key A is pressed it adds Letter to an array.
static Letter[] letters = new Letter[50]; // all letters to be shown
static int letterCounter = 0; // last array element
public static Vector2 Cursor = new Vector2(10, 10);
public static void Update()
{
keyState = Keyboard.GetState();
Checker();
oldKeyState = keyState;
}
static void Checker()
{
if(IsKeyPressed(Keys.A))
{
characters[letterCounter] = 'a';
letters[letterCounter] = new Letter('a');
Cursor.X += 20;
letterCounter++;
}
}
All letters in array should be drawn, but aren't, only the last element in array is drawn.
public static void Draw(SpriteBatch spriteBatch)
{
for(int i = 0; i < letterCounter; i++)
{
letters[i].Draw(spriteBatch);
}
spriteBatch.DrawString(font, ("Letter 0: " + (letters[0] == null)), new Vector2(10, 50), Color.Black);
spriteBatch.DrawString(font, ("Letter 1: " + (letters[1] == null)), new Vector2(10, 70), Color.Black);
}
As you can see I also tested if previous elements are maybe null for some reason, but they aren't, they are all valid objects I think but just the last one in array gets drawn :/
EDIT: