Developing XNA Apps in Visual Studio 2012

Have been trying to find a way since there is no official release for XNA GS in Visual Studio 2012 even its Release Candidate.

But i've found something not a good idea but works anyway.

If we dont want to use XNA's Content Pipeline then what worse things can come out of it: 
Well, much more lines of code!

Now, create a new Class Library Project in .NET Framework 4.5(later we'll transform it to Windows Application)
Add reference from a .NET Framework 4.5 project as its displayed there you cant see XNA .dlls as a reference but as an extension!
ss1.png

So we've added the .NET 4.0 extensions for XNA Framework

Now its better we write a Program.cs file and set it as a Startup Project

Program.cs:

using System;
namespace XNAProject2
{
static class Program
{
static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}
Later we set it as Startup Object from Project-> [YourProjectName]Properties

Now lets create a new Game class and add codes for it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace XNAProject2
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;       
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);            
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);            
}
}
}

Here we are!

Now lets run it if it will run or not:


ss2.png


OK. That was a nice punch to the face. I admit!

Why this problem occurs because of lack of 64-bit support for previous .NET framework references which we call extensions.

Now head over here:

ss3.png


and change as it seems:

s4.png


After you change it to x86 it must have worked nicely

ss5.png

An empty screen drawn with CornFlowerBlue Color works as it should be while working with XNA GS.

Now why dont we just fill it?

Lets add a sample sprite it render it inside XNA project:

Lets add a picture inside  your project.i added a performer png file,you can your own.

Add these variables for x,y corrdinates,width and height of the sprite and the object that we will create sprite from "Texture2D"


 int x=10;
int y=10;
int width=256;
int height=256;       
Texture2D pic_texture;


Inside LoadContent add these codes:

 pic_texture = Texture2D.FromStream(GraphicsDevice, TitleContainer.OpenStream(@"performer.png"));

Here we set up our texture2d object to load an external image file through a path - which is in the same place as code files -
Then in Draw add these codes:

 spriteBatch.Begin();
spriteBatch.Draw(pic_texture, new Rectangle(x, y, width, height), Color.White);
spriteBatch.End();
Here we render our sprite with given texture file,x&y coordinates,width and height of the sprite shall be.

Lets run it!

And display our sprite:

ss6.png


Thats good!

Even though XNA GS wasnt installed,you've succeeded on developing for XNA platform(Windows only) in Visual Studio 2012.

I do hope that it works in Windows 8 as well even though i was doing this work in Windows 7 system.

Hope this article helps you on your studies

Feel free to drop a comment if you disagree with me the way I suggest here.
Have a nice day!

Up Next
    Ebook Download
    View all
    Learn
    View all
    Araf Global is a software consultancy company founded in 2016 focusing on cutting edge technologies.