XNA basic tut

Tutorials on how to use and create games in XNA.
1 post Page 1 of 1
Contributors
User avatar
reececlarke
VIP - Donator
VIP - Donator
Posts: 245
Joined: Tue Dec 08, 2009 6:47 pm

XNA basic tut
reececlarke
well this will be my first tut
before I start i have only worked with XNA for 3 days and c# for 3 days too but i will be sharing what i know so far

to start with you will need to put the images you want to have in your game into the content pipeline to do that right click content and add existing item and find your image.

next what you will be wanting to do is in the part where it says "public class Game1 : Microsoft.Xna.Framework.Game
{"
add in
Code: Select all
Texture2D yourimagenamecanbewhatever;
Rectangle canalsobewhatevertoo;
Texture2D declares a 2D image but it currently is not anything so you will need to load it in the protected override void LoadContent()
{
Code: Select all
youimagename =  content.load<Texture2D>("thefilenameitself e.g"image" you dont need / or anything like that");
 your Rectangle = new Rectangle(x,y,x size of it,y size of it);

this code pairs up the image to the refrence and the rectangle to the rectangle ref


what we now need to do is draw it in so under protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
Code: Select all
 spriteBatch.Begin();

spriteBatch.Draw(yourimage,yourRectangle,Color.White);

spriteBatch.End();

.begin shows where it is going to start drawing so the things at the top go to the bottom of it like the back grounds will be at the top and the player will be at the bottom

.end shows where it will end
and in the middle is the .draw command this tells it to draw your image in a good thing to note is that color.white makes your object you made keep the colours it has any other colour will put a tint on it.


and there you go a basic image in xna i hope this helps you =]

Ps a like always helps so if i helped u please like =] :D
Image
1 post Page 1 of 1
Return to “Tutorials”