Lesson 4: The More the Merrier
In this short lesson we'll look at drawing more than one sprite on the screen.
Project code for this lesson:
http://www.bluerosegames.com/xna101/lessons/XnaLesson4.zip
We can use the same texture to draw more than one sprite. All we need to do is to add another SpriteBatch.Draw() method call specifying the same texture object as the first argument to the method.
In our program from Lesson 3, go to the Draw() method of Game1 and find the following line:
spriteBatch.Draw(spriteTexture, new Vector2(0f, 0f), Color.White);
Add another copy of this line of code directly after the first one, then change the (0f, 0f) to (175f, 175f) so that the code now looks like this:
spriteBatch.Draw(spriteTexture, new Vector2(0f, 0f), Color.White);
spriteBatch.Draw(spriteTexture, new Vector2(175f, 175f), Color.White);
Now run the program, and you should see something like this:
Simple as that. This can be repeated for as many sprites as you want. You can also define and load more Texture2D objects and have sprites that are different images.