XNA 101 .Net

Learn how to program in C# while writing games in XNA Game Studio 3.0!
Our upcoming Silverlight book for beginners (includes a great chapter on game development in Silverlight!) Hello! Silverlight 2 with Dave Campbell, available online now!



Pages

Recent posts

Navigation

Archive

Blogroll

    Tampa Divorce Lawyer

    North of Tampa in Lutz, Florida. A Tampa Divorce Lawyer focusing on family, divorce, and real estate law.

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    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.

    Posted: Oct 09 2008, 12:44 by Bill Reiss | Comments (1) RSS comment feed |
    • Currently 5/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5
    Filed under:

    Comments

    Comments are closed