Download The Project
You've developed a game and now you'd like users to capture screen to show their friends or share it via social media accounts,then read & follow the steps in this article.
It will help you a lot.
To get started,create a new xna windows game.
Add reference to these:
And then import them using:
Then add these variables on your project:
Bitmap screen = null;
int a = 1;
"screen" variable will be used to capture the screen, "a" variable will be used while saving as output.
Now in Update function we will control if any key pressed,if true then we will capture the screen and save it as a output.png(it will be named output1.png,output2.png - depending on "a" variable)
KeyboardState stat = Keyboard.GetState();
System.Drawing.Rectangle bounds = Control.FromHandle(Window.Handle).Bounds;
screen = new Bitmap(bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(screen))
g.CopyFromScreen(new System.Drawing.Point(bounds.Left, bounds.Top), System.Drawing.Point.Empty, screen.Size);
screen.Save("output" + a + ".png", System.Drawing.Imaging.ImageFormat.Png);
a += 1;
the bounds are the sizes of our XNA Window,if they were'nt we would have captured full screen Windows.
As you can see we used classical Windows way as its going to work only for Windows then why not use it?
Now lets run it and see.Press Escape key and it will create outputs automatically:
Hope that helps!
To display all the colors,i've used combobox from windows controls
First of all we need to get the Type of Color:
Type structType = typeof(Color);
Then we use PropertyInfo to get all the controls:
PropertyInfo fields = structType.GetProperties();
The reason why we didnt use FieldInfo instead of PropertyInfo is Each color is actually Property and have fields like R,G,B,A.
So we iterated through PropertyInfo and populated our combobox object
foreach (PropertyInfo field in fields)
When we run it,we'll be getting extra useless items:
So what to do?
I've written a simple iteration to remove these useless items:
for (int a = 0; a <= 5; a++)
it removes the first 6 items from the list.
Simple but useful.As it seems:
Our work is done here.We got our Colors populated.
Hope it helps
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!
Download the Project!
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!
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
static class Program
static void Main(string args)
using (Game1 game = new Game1())
Later we set it as Startup Object from Project-> [YourProjectName]Properties
Now lets create a new Game class and add codes for it:
public class Game1 : Microsoft.Xna.Framework.Game
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
protected override void Initialize()
protected override void LoadContent()
spriteBatch = new SpriteBatch(GraphicsDevice);
protected override void UnloadContent()
protected override void Update(GameTime gameTime)
protected override void Draw(GameTime gameTime)
Here we are!Now lets run it if it will run or not:
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:
and change as it seems:
After you change it to x86 it must have worked nicely
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"
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.Draw(pic_texture, new Rectangle(x, y, width, height), Color.White);
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:
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!
I was curiously experimenting WP7 Emulator to find something how XNA runs in Windows Phone 7 Emulator for a loong time
I've found it last year before going to army service but wanted to show you,absolutely! Im not so sure about it but i think XNA Applications running on Emulator are being hosted inside another Silverlight Application.Because of Emulator simulates the real device its quite strong possible that the XNA apps written for Windows Phone 7 being simulated inside a Silverlight Canvas.
How did i come to this conclusion?
I've tried to get to know what Current Application inside Emulator does and found out that its the application object running at that time.But its specific to WPF/Silverlight so a little bit cheating on it doesnt hurt and i did as it is.
I've written these codes to get the Current Object running xna game is being displayed and where its hosted:
So after running this,i got what i wanted and somethings are now clear on my mind.
So after saw this output,the first thing came to my mind was the GPU Support for Silverlight.So the reason adding GPU Ability to Silverlight was to run XNA inside Silverlight Host or something else?Hmm.i'd better keep drag more! I'll let you know about the events.
Update: Ok guys my suspicions were right.XNA apps on WP7 runs inside a Silverlight Host.
I asked it on Twitter
But i dont know why? Only Guys-From-Microsoft can answer that :)
Maybe its for using Lauchers,Choosers in short terms for using all the task system inside xna? Just theory.
Assuming you need to show a MessageBox in an XNA application on WP7,the easiest way is to add System.Windows namespace.
Then you need to call "Classic" Show function of MessageBox
Here have a look at what we've achieved:
Hope it helps!
i have been working for building a library.It can be used for WindowsPhone7,XBOX 360 & Windows Game projects.
its not finished yet but im willing to give you a shot
i called it "REXLibrary"
Here are whats included in this library:
Best,i'd better keep working on it