I am trying to draw lots of instances of an image using the following code:
PictureBox[] sprites = new PictureBox[100];
private void Game_Load(object sender, Ev
You're only actually creating one instance of PictureBox
:
PictureBox mainSprite = new PictureBox();
...
for(var i = 0; i < sprites.Length; i++)
{
sprites[i] = mainSprite;
Your array will have lots of reference to the same object. You should create a new PictureBox
on each iteration of the loop:
for(var i = 0; i < sprites.Length; i++)
{
PictureBox mainSprite = new PictureBox();
mainSprite.Size = new Size(16, 16);
mainSprite.Image = img;
sprites[i] = mainSprite;
...
}