[TuT]Xna 3.1 Tutorial: Sprites
He everyone, I'm going to give you a short, simple tutorial on how to:
- Load Sprites to the Content Pipeline
- Store the Sprite using Texture2D
- Load the sprite into the LoadContent Method
- Draw the sprite onto the Screen
1. Easily Create a new project from the main menu screen, I don't care what you name it.
2. Now we will load our sprites that we have already downloaded/made. I will be using a somewhat smiley face.

3. Since we have our content in the content pipeline we will need to store it somewhere in the code to keep all the assets and proporties for it. We will do this by placing the line of code below in your Game1 class.

4. Now we have our variable that will hold all our stuff we need for that sprite, we will have to use the LoadContent Method, to tell the program to load the information necessary avoiding a lot of code.

The syntax is [ object = content.load<object type>("asset name") ]
To find the asset name it will be in the properties of the sprite where it says 'asset name':

5. We have to go ahead to write the code to draw the sprite from our content that we loaded. Before you decide to draw the sprite, you will need to know the position where you want to draw it. You will do this by placing another variable in your Game 1 class:
This code is telling us that we want to create a new variable with the name playerPosition, and tell it what the coordinates are. XNA Goes from 0,0 -> 800x600. It does not go negative.

6. Okay, we have the Position and the Sprite already to go lets draw it on the screen. We will do this by going to the Draw method and placing this code:
By telling xna Draw method we want to draw using 3 arguments which are the texture(the variable hold the sprites info), the vector(where it is going to show up on the x, and y axis, and to use the color white so no clipping or shading appears incorrect.

Thanks for reading.
Tutorial 2: Character movement will be out soon!
If you need more in-depth information on certain things that I use while programming please PM so we don't have to clutter the thread!
Constructive criticism is a +
- Load Sprites to the Content Pipeline
- Store the Sprite using Texture2D
- Load the sprite into the LoadContent Method
- Draw the sprite onto the Screen
1. Easily Create a new project from the main menu screen, I don't care what you name it.
Code:
File > Create New Project > "Enter Name" > OK
Code:
Solution Explorer > Right Click content > New > Existing Item > Browse for the item than add it

3. Since we have our content in the content pipeline we will need to store it somewhere in the code to keep all the assets and proporties for it. We will do this by placing the line of code below in your Game1 class.
Code:
Texture2D playerTexture;

4. Now we have our variable that will hold all our stuff we need for that sprite, we will have to use the LoadContent Method, to tell the program to load the information necessary avoiding a lot of code.
Code:
playerTexture = content.load<texture2d>("player")

The syntax is [ object = content.load<object type>("asset name") ]
To find the asset name it will be in the properties of the sprite where it says 'asset name':

5. We have to go ahead to write the code to draw the sprite from our content that we loaded. Before you decide to draw the sprite, you will need to know the position where you want to draw it. You will do this by placing another variable in your Game 1 class:
Code:
Vector2 playerPosition = new Vector2(100,100)

6. Okay, we have the Position and the Sprite already to go lets draw it on the screen. We will do this by going to the Draw method and placing this code:
Code:
spriteBatch.begin(); //telling to start drawing spriteBatch.draw(playerTexture, playerPosition, color.white); spriteBatch.end(); //stop drawing

Thanks for reading.
Tutorial 2: Character movement will be out soon!
If you need more in-depth information on certain things that I use while programming please PM so we don't have to clutter the thread!
Constructive criticism is a +


Thank you very much!