Reader Level:
ARTICLE

Developing XNA Apps in Visual Studio 2012

Posted by Ibrahim Ersoy Articles | Visual Studio 2012 July 05, 2012
While I was searching for a way to make it real, I found a not-so-well adviced technique by not using XNA GS and its easy implementations.
  • 4
  • 0
  • 62958
Download Files:
 

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!

Article Extensions
Contents added by Armando Diaz on Oct 22, 2012

Great Article.. i found a decent work around also..
by installing a VS2010 Isolated Shell i was able to install XNA Game Studio.

I found that installing SQL Management Studio 2012 installed the Isolated Shell for me, since it was a tool i use often i didn't have to download the Isolated shell.

From here i copied the XNA Game Studio Folder from

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft to

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\MicrosoftC:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft

then changing the line for Visual Studio Version in file extension.vsixmanifest from 10 to 11. i was able to get it work fine in VS2012

you may have to run devenv.exe with a /setup to have VS reconigize the changes.

Contents added by Simon Jackson on Oct 15, 2012
A great post, just mentioned it in my Recent Windows 8 and XNA article (http://bit.ly/PxSlHc).  Previously I had thought WinForms was the only route but this is much cleaner.

I've tested it in the RTM and it also now works in all configuration options as well.

Great stuff

P.S.
I've also managed to work out the Content builder part of the equation as well in that article.
COMMENT USING

Trending up