top of page

XNA  BASIC

Hey All.....

 

Today I am gonna show you very small small basics of XNA.

I completely understand Microsoft had stopped supporting development of XNA,but there are still lot of benefits of XNA.For me specifically one benefit is-You can Convert XNA game to ANDROID,IOS,WINDOWS DESKTOP and PHONES,TABLETS etc.(see my XNA to MONOGAME article)

 

This is why XNA is still valuable.

 

Ok,Lets start-

 

First Remember for developing a XNA game,You need to remember 3 things-

1.Load a content(may be image,sounds,fonts etc.)

2.Draw this Loaded Content into UI(window)

3.Update this Drawn Content.

 

So,Lets start doing a small project-

1.Install Visual Studio

2.Install XNA Game studio-

 

https://www.microsoft.com/en-in/download/details.aspx?id=23714

 

3.Go to Visual studio,FILE->NEW->PROJECT

It will open a new project,Here in solution Explorer you will see a Game1.cs file.

This is the file you need to play on.In this file you will see three basic methods-

Loadcontent,Updatecontent,DrawContent.

 

LoadContent is basically used to load contents(images,sounds,fonts etc.) in memory,

that means just to load somewhere in device.

Now lets load our player image.

 

For that you need to declare a variable like this-

 

Its time to load this texture .Go to you loadcontent method and declare like this and copy your image into your Solution's Content project-

Your image is loaded somewhere in device,now we need to show that image in device that means you need to draw that in Draw method like this-

Note -You need to declare spriteBatch.Begin() before drawing textures and declare spriteBatch.End() after drawing all textures

 

Now build the Solution ,You will see your image has been drawn.

What about update method??

Well ,update method is used to manipulate(move,jump,shoot etc.) the loaded textures,sounds etc.

 

For that let us declare a variable for our player Texture i.e. Rectangle .

Rectangle is like container which contains our textures.

 

 

 

 

 

 

 

Now we need to load this rectangle in Loadcontent for our Player texture like this-

 

playerRectangle=new Rectangle(playerTexture.Width,PlayerTexture.Height,200,200)

 

Now Replace  spriteBatch.Draw(PlayerTexture,new Vector2(100,100),Color.White) to

spriteBatch.Draw(PlayerTexture,playerRectangle , Color.White);

in Draw Method.

 

 

In Update Method Replace your codes like below-

In Xna Update and Draw method executes 60 times in every second,So here what happens is our player Container i.e. PlayerRectangle's X Position increases by 5 in every second,so when you build the solution,You will see your image will be moving.

And if PlayerRectangle's X position is more than 1000,then player again comes to X position 20.

 

 

So...Now Like this a Game is developed ,These are basics.To explore more Watch these Videos.I specifically learnt from there and published two simple and high quality games-

 

https://www.youtube.com/watch?v=YQiQOYXnrkw&list=PL667AC2BF84D85779

 

 

But before That Please explore more and more ,what ever I explained here..like 

changing color of texture by Colors.Green ,Shifting Y position instead of X position etc.

 

Ok guys..Please Contact me If you face any problem regarding this,I will be very happy to help you.Also Please Downlaod my Apps and Games,details are in my blog section,It will be helpful to me.

 

bottom of page