XNA Essentials

Game Programming for Xbox 360, PC + Windows Phone

NAVIGATION - SEARCH

XNA Game Studio 4.0

On September 16th, the XNA Framework team will be releasing XNA Game Studio 4.0.  While games created for the Xbox 360 will still be based on XNA Game Studio 3.1 for the near future, the team is also releasing a beta version of the new Connect tool (that allows you to connect your development machine to your Xbox 360 to transfer your XNA games) on the same day.

September 16th is when the Windows Phone 7 tools will be launched as well.  The timing isn’t coincidental since the Windows Phone 7 will allow developers to create games and apps using either Silverlight or XNA Game Studio.  The tools have been in beta for a while now.  The actual Windows Phone 7 Series devices will be released sometime this holiday season.

XNA Game Studio 4.0 has breaking code changes. The XNA Framework team went with the mantra of “If you break it, break it good.” They went with a  new approach of Reach vs. HiDef.  Reach is being able to write the same code for all supported platforms – Windows, Xbox 360, Windows Phone 7. HiDef is targeting a particular platform and the specific features it has available.  This was a great move and while it causes discomfort in updating any existing code it makes a stronger base for bringing in even more platforms in the future.

Make sure you grab the tools as soon as they are available in a couple of days!

I certainly hope that all of my readers read Shawn Hargreaves blog regularly. I’ve only linked to a couple of his posts here about XNA Game Studio 4.0, but he has a wealth of information that you will find beneficial. So make sure to catch up on his blog posts if you haven’t already.

Happy Programming!

-Chad

CodeStock 2010 Presentations

This was the first year I had attended CodeStock. It was an excellent conference.

I had two sessions – XNA Crash Course and Artificial Intelligence. Hit the links to download the slides. As with most of my talks there isn’t a lot to the slides as most of the time is spent in either demos or me talking about the points. Still, I’ve included them here just in case they help anyone.

I had detailed my experience at CodeStock but determined this was not the right blog for that sort of post.  I’ve been wanting to create another blog that covers general development and other ramblings I may have.  I will launch that soon and post the link here in case anyone cares about my non XNA adventures.

I will sum up my experience by saying that the .NET Developer community is awesome.  If you aren’t involved – get involved. You will not regret getting to know other folks that get excited by the same technology that you do.

Happy Networking!

-Chad

CodeStock 2010 for Developers, IT Pros and Entrepreneurs

I’ll be speaking at CodeStock in Knoxville, TN on June 25th and 26th.  I have two sessions I’ll be presenting:

I was pleased and very surprised to see that my Artificial Intelligence talk was voted as number 3 of sessions the folks wanted to attend.

 Join me at CodeStock

If you haven’t registered yet, you should.  Rachel Appel, now a Microsoft employee, will be giving the keynote.  I’ve always enjoyed hearing Rachel’s talks.  If you are interested you can even view my current schedule for the two day event.

nerdetteskull_2010_lowres

Direct from CodeStock’s Marketing Department:

The theme for CodeStock 2010 is about connections.  Connecting with peers and building a professional network.  Connecting with IT roles outside of your own.  Connecting with the people who can help make your ideas reality.

  • Keynote by Microsoft Developer Evangelist Rachel Appel
  • Sessions for Developers, IT Professionals, and Entrepreneurs
  • 100+ break out sessions + Open Spaces (self-organizing sessions)
  • Panel discussions and live podcasts
  • CodeStock Social Event to meet and make connections

Space is limited so register today at CodeStock.org

So if you are within driving range, you really should register.  I’ve never been to CodeStock but I know the organizer personally and I understand the food is great on both days.  I also know a lot of work has gone into this event and it has grown exponentially every year.  So buy a ticket and come join the fun!

Happy Learning!

-Chad

Getting Started with XNA Game Studio 3 Hands On Lab

This is a lab I originally created for the Carolina Code Camp. The lab covers two main items:

Platformer Starter Kit

  • Creating the Platformer Starter Kit
  • Compiling and Running Platformer
  • Modifying Level 1

Indeterminate Progress Bar

  • XNA Framework 2D Basics
  • Creating an Indeterminate Progress Bar Demo
  • Drawing 2D Text

 

The lab is adapted from my Microsoft XNA Game Studio 3.0 Unleashed book.

Download the lab and give it try. It takes about an hour to complete.

Happy Programming!

-Chad

Making Money by Making Games with XNA

I’ve done this presentation a couple of times so far. The PowerPoint presentation without the actual talk doesn’t mean too much by itself, but I have included it as is for folks to refer back to that attended the talks.

Everyone can feel free to download it.

The core of the talk is about best practices when developing games for the Xbox 360 to be sold on Xbox LIVE Marketplace as an Xbox LIVE Indie Game (XBLIG). The slides also mention some ways to use the same code written for the XNA Framework to then be repurposed for a Silverlight game thanks to SilverSprite and even for the iPhone thanks to XNATouch and MonoTouch and Mono.

The best practices section was taken from the chapter in my book “Best Practices for Creating an Xbox LIVE Community Game”.

The last section (bonus!) talks about developing games for the Zune HD. For more information, check out my original blog post where the code can be downloaded.

Happy Programming!

-Chad

The Kewlniss Func

Michael Neel (aka @ViNull) interviewed me at the Raleigh Code Camp back in September for his Feel The Func podcast. He edited a little bit, but it is still almost 2 hours in length.

If you are interested in listening to us chat about the game he is making, my book, the XNA Community in general some games we play as well as some XNA topics such as Rich Presence feel free to listen.  I’m sure he’d love you to subscribe.

Also, a much better interview is the one he did with Jame Silva of The Dishwasher: Dead Samurai fame. So make sure to check his interview out too.

Happy Listening!

-Chad

Zune HD Scribble Test – Source Code

I did a talk yesterday at the Raleigh Code Camp. It went well I think. If anyone was at the talk and would like to give me feedback, feel free. The only way I’ll get better is if I know how effective / non effective the talk was.

It is always interesting trying to give a talk to an audience with people who have no clue what XNA is as well as those who have been fooling with it for a year or more. Ultimately, there are parts where both parties are bored – but hopefully not at the same time!

Anyway, while the talk was more about best practices for XBLIG and what you need to do to submit games to ultimately make money using XNA, we did spend the last 10-15 minutes of the session looking at a scribble app I made for the Zune HD on Friday night before the session.

Rob Zelt mentioned on twitter that I may have very well been the first person to do an XNA talk with a demo for the Zune HD at a Code Camp. Seeing how the Zune HD was just released this past week and typically Code Camps are held on Saturdays and I had the second session of the day at 9:40 EST I think he may be right. For some reason that makes me smile. A geeky gold star for me.

OK, now to the actual project. You can download the project and look at the comments to see what it is doing. I also did a brief video on it Friday night after I got it working.

At a high level, the code is simply looking at the touch panel collection to see all of the points / vector2 that were moved. It grabs the starting and ending point for this move and adds it to a list. We then draw a line from the starting point to the ending point and do that for each line segment in our line list. To erase it, we just shake the device. Really, we are just checking the difference of the acceleration on the X or Y axis to see if it has moved a certain amount in a frame. This way if someone just moves it slowly or turns it the screen won’t erase, but if it is a fast enough motion (easily produced by shaking) then we clear the line list so there is nothing to draw. The demo code also collects the rotation of the device from the accelerometer as well as the acceleration, but doesn’t actually use the rotation values.

Hopefully this will give you an idea of what is needed, but you should definitely check out the documentation from XNA Game Studio. In order to run this, you will need a Zune HD as well as the latest XNA Framework which comes in XNA Game Studio 3.1 Zune Extensions.

Download Zune HD Scribble Test

Happy Coding!

-Chad

Raleigh Code Camp – September 19th, 2009

If you are near the Raleigh, NC area on September 19th, 2009 you should really drop by the free Code Camp. If you have never been to a code camp, it is an event put on by a local user group. The events are free to the folks that attend. The folks that give their time to run the user groups and organize the code camps find sponsors who pay for the food, swag and everything else that goes into putting on these events.

If you aren’t in this area, you should definitely check around to see if there is a .NET User Group in your area. I attend one locally here in Greensboro, NC where we meet the first Tuesday of every month. We will be meeting tomorrow night, September 1st at the usual place.  The talk tomorrow night is on “Mashing up MVC, Bing, Maps and Flickr”. It should be good.

Again, it is really beneficial to get plugged into your local developer community. What better way than through events like User Groups and Code Camps?

The session list for the Raleigh Code Camp promises to have some excellent content. If you are interested in XNA you can hear me talk, but there are tons of other subjects that are interesting as well. There are talks on jQuery by Rachel Appel and Kevin Griffin, Database Design by Andy Leonard, Blend for Developers by Diane Wilson, LOB Apps with Silverlight 3 with Jim Duffy, general guidance on making high quality .NET applications with Chris Love, TDD with Steve Andrews, Dynamic Language Performance with Kevin Hazzard, UX in Silverlight with Rob Zelt and many others. The quality of speakers for this event is really great. I’m privileged to be speaking at the same event as these folks.

Again, to better ourselves as Software Engineers it is crucial for us to continue to learn. A great way to do that is to get with like minded people and User Groups and Code Camps provide an extremely cheap (FREE) way for us to connect with others.

Happy Networking and Learning!

Chad

Dream Build Play 2009 Challenge Submissions Due Today

Make sure that you get your XNA Game Studio 3.1 game submitted to the contest today. Show Microsoft what you have been working on for the last 4 months or more. Grand prize is $40,000. Do not wait until the last moment to try and upload your game. Head over to http://www.dreambuildplay.com/ and submit your game now!

Hope everyone does well!

If you submitted your game to the DBP competition and want to show off your work, feel free to post in the forums. The forum is also for any XNA work that has been done. Make sure to read the Showcase Guidelines before posting.

Happy Sharing!

-Chad

Advanced Debugging Tutorial – Part Two

In the first tutorial we talked about some of the advanced debugging techniques. In this tutorial we will take it a step further and create a debugger visualizer. When we look at data while debugging, sometimes the default representation isn’t quite good enough. For example, the value of a Matrix variable is displayed as simply a string. We could make it into a table structure that actually represents the Matrix. We could also actually display the real color instead of just the color name or RGBA values.

In this tutorial we will be creating a color visualizer. When creating a debugger visualizer there are a few steps that have to take place. We need to do a few more things to get the visualizer be a Windows form that utilizes XNA.

image

Typically one would do the following steps to create a normal visualizer:

  1. Create a class library projects
  2. Add appropriate references (Microsoft.VisualStudio.DebuggerVisualizers; System.Windows.Forms)
  3. Create a class and make the class inherit from the abstract class DialogDebuggerVisualizer
  4. Override the Show method from the abstract class
  5. Add the assembly attribute DebuggerVisualizer setting the appropriate properties
  6. Copying the compiled assembly into one of two folders so Visual Studio can load it and use it

We will be altering the earlier steps a little since we are going to start off with a Creators Club Online Educational Example. We want our windows form to actually utilize XNA and there is no reason to reinvent the wheel. Let’s get started!

Start with the Educational Example: WinForms Series 1: Graphics Device

Extract this to a new folder called XNAVisualizer

Rename the project to XNAVisualizer

Rename the solution file to XNAVisualizer.sln

Open the solution file and rename the project in the Solution Explorer

Rename all of the namespaces to XNAVisualizer.

A shortcut for renaming all of the namespaces is to change one name and then click on the dropdown it makes and select “Rename ‘WinFormsGraphicsDevice’ to ‘XNAVisualizer’

image

Change the project type from Windows Form to Windows Library.

Double click on the Properties node in the Solutions Explorer. Under the Application tab change the Output Type from Windows Application to Class Library

image

While we have the properties window open, we can change the Assembly Name to XNAVisualizer

Delete the SpinningTriangleControl from the project.

Rename SpriteFontControl to ColorControl

We will be adding this control to the form later. This is the control that will display the color being debugged.

Add the following public field to the new ColorControl

public Color BackgroundColor = Color.CornflowerBlue;

Change the contents of the ColorControl’s Draw method to contain:

GraphicsDevice.Clear(BackgroundColor);

spriteBatch.Begin();
spriteBatch.DrawString(font, BackgroundColor.ToString(), new Vector2(10, 10), Color.Black);
spriteBatch.DrawString(font, BackgroundColor.ToString(), new Vector2(11, 11), Color.White);
spriteBatch.End();

In the Initalize method replace the following line:

content = new ContentManager(Services, "Content");

with these three statements:

Assembly visualizerAssembly = Assembly.GetExecutingAssembly();
content = new ContentManager(Services);
content.RootDirectory = visualizerAssembly.Location.Replace(
    visualizerAssembly.ManifestModule.Name, @"Content\"); 

Since this assembly will be running in a special folder we need to explicitly tell it where it can find the Content assets. We are using the Arial font from the original project. We are displaying the Color’s RGBA values using the font. The code is using reflection to get the executing assembly (our visualizer) and then setting the path to the path of the assembly and appends Content\ to the end of it. The Location property contains the full path including the assembly name (XNAVisualizer.dll). The ManifestModule.Name contains the assembly name as well. We are simply removing the assembly name from the path.

Since the code is using reflection we need to add the following using statement to the top of our ColorControl.cs file:

using System.Reflection;

 

Now we can bring our attention to the MainForm.

Remove all controls from the MainForm form

Double click on the MainForm.cs file

Click Ignore Errors and Continue

Remove the combo boxes, the split panel and delete each one. You may have to right click on the form and choose Select ‘spltContainer1’. Once it is selected you can hit the Delete button on the keyboard to remove it.

Make the form itself a lot smaller. For this we are simply wanting to display the color and the RGBA values of the color so it doesn’t need to be too large.

Compile the project and double click on the error to bring us into the MainForm.Designer.cs. Remove the SpinningTriangleControl and vspriteFontControl variables.

Remove the vertexColor_SelectedIndexChanged method from the MainForm class.

Remove the three vertexColors from the MainForm constructor.

Recompile to see 0 errors.

Open the design view of the MainForm again.

Re-add the ColorControl directly to the form by dragging it from the toolbar (under XNAVisualizer Components)

Expand the ColorControl so it fills up the entire form.

Change the form’s FormBorderStyle in the properties panel to FixedToolWindow. This keeps the window from being resized.

Change the Text of the window to “XNA Color Visualizer”

Drag the ColorDialog (from the toolbox under either the All Windows Forms or Dialogs tabs) to the form. This will create colorDialog1.

Double click on the ColorControl to create the _Click event.

Replace the contents of the MainForm class with the following:

public MainForm()
{
    InitializeComponent();
} 

public XnaColor Color
{
    get
    {
        return (colorControl1.BackgroundColor);
    }
    set
    {
        colorControl1.BackgroundColor = value;
        colorControl1.Invalidate();
    }
} 

private void colorControl1_Click(object sender, System.EventArgs e)
{
    if (colorDialog1.ShowDialog(this) == DialogResult.OK)
    {
        Color = new XnaColor(colorDialog1.Color.R, colorDialog1.Color.G, colorDialog1.Color.B, colorDialog1.Color.A);
    }
}

We added a public property Color. The example code declared XnaColor as a type to help distinguish from the XNA Color and the Windows Form Color. We are using the XnaColor type. We simply return the BackgroundColor of our colorControl when Get is called. And for Set we, we set the background color of the control as well as Invalidate our control so it will be redrawn. We could have hooked into the Idle event and called Invalidate continually, but there is no need for this control. The original example does this with the SpinningTriangleControl. Reading the WinFormsGraphicsDevice.htm file would be beneficial to see the pieces of the code we are using but not discussing like GraphicsDeviceControl, GraphicsDeviceService and ServiceContainer.

We populated the colorControl1_Click method by actually displaying the built in Windows Color Dialogbox. If the user clicks OK, we get the selected color from the dialog box and set our color property to the newly selected color. Our color property then sets the BackgroundColor property of the ColorControl. Note: This control does not let us change the Alpha value of the color.

 

The last thing we need to do is actually create our Visualizer code.

Add a new blank code file and name it ColorVisualizer.cs.  Paste the following code:

using System.Diagnostics;

using Microsoft.VisualStudio.DebuggerVisualizers;
using Microsoft.Xna.Framework.Graphics;

[assembly: DebuggerVisualizer(
    typeof(XNAVisualizer.ColorVisualizer),
    Target = typeof(Microsoft.Xna.Framework.Graphics.Color),
    Description = "XNA Color Visualizer")]

namespace XNAVisualizer
{
    public class ColorVisualizer : DialogDebuggerVisualizer
    {
        protected override void Show(IDialogVisualizerService windowService,
                                     IVisualizerObjectProvider objectProvider)
        {
            Color c = (Color)objectProvider.GetObject();

            using (MainForm form = new MainForm())
            {
                form.Color = c;

                windowService.ShowDialog(form);

                if (objectProvider.IsObjectReplaceable)
                {
                    if (form.Color != c)
                    {
                        objectProvider.ReplaceObject(form.Color);
                    }
                }
            }
        }

    }
}

We have to add a reference to the Microsoft.VisualStudio.DebuggerVisualizers assembly by clicking on the References tree node in the Solution Explorer under the XNAVisualizer project. Making sure we are on the .NET tab we scroll down and select the assembly and add it to our references.

The assembly attribute DebuggerVisualizer tells VisualStudio this is the entry point for the visualizer. It tells it what type of data it is visualizing as well as the description.

The visualizer class itself inherits from the DialogDebuggerVisualizer abstract class. We override the Show method to actually display our form with the data being investigated by the debugger. We look at the objectProvider object passed in and cast it to our Color type. We set the Color property on the MainForm to the value we are debugging. We then actually display the MainForm by calling ShowDialog on the windowService object passed in.

If all we wanted to do was display the color we would be done. However, it would be nice to actually change the color on the fly while debugging. This is why we added the Color Dialogbox. We first check to see if the object we are viewing is replaceable. It won’t be replaceable, for example, if we are debugging an enumerated type (i.e. Color.Black). However, if it is a variable holding a value then it will be replaceable and we replace the object by calling ReplaceObject on the objectProvider object passing in our new object (form.Color in this case). There is also a ReplaceData method, but we aren’t discussing that in this tutorial.

After compiling the assembly we need to place it in one of two directories:

\$Documents\Visual Studio 2008\Visualizers

or

\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers

Since we have Content assets we also want to copy the Content folder and any assets to the Visualizers folder as well. It can be tedious to copy the assemblies and content assets after every compile. We can create a Post Build Event command line to copy it for us. We need to open the properties of the XNAVisualizer project (by double clicking on the Properties node in the Solution Explorer) and go to the Build Events tab. Click on the Edit Post-build button and paste the appropriate variation of the following command and hit OK:

copy "$(TargetPath)" "C:\Users\<User Name>\Documents\Visual Studio 2008\Visualizers"
md "C:\Users\<User Name>\Documents\Visual Studio 2008\Visualizers\Content"
copy "$(TargetDir)\Content\*.*" "C:\Users\<User Name>\Documents\Visual Studio 2008\Visualizers\Content"

(Change the paths as needed)

Now when we run a regular XNA project and we want to debug the color we simply set the breakpoint and when we hover over the color variable we want to debug we click the Magnifying Glass icon which will bring up our newly created form.

Fortunately, the XNA Framework team did a lot of the heavy lifting for us (as usual) in this example by allowing us to utilize XNA in a Windows Form. We simply modified the example to be a Class Library and added the actual Visualizer code.

Debugging the Debugger Visualizer

To debug a debugger visualizer a static test method can be created and then a console app can be created to call the static method. This can be a great way to test the visualizer. Instead of creating a console app with all of the XNA assemblies referenced, I debugged the visualizer by  attaching to another Visual Studio instance.

In the Debugger Visualizer project click on Debug / Attach to Process. A dialog will come up. Select Visual Studio instance you want to debug. This would be your real XNA project that has a XNA Color variable.

image

Now when we set a break point in the main XNA project and hover over a Color variable and hit the magnifying glass it will kick off the Visualizer Debugger and if we had a breakpoint we could step though the code. Pretty cool!

 

A great next step would be to create another visualizer in this project to display Matrices.

For more reading on Visualizers look in the following here.

Download the code from this tutorial here.

Happy Coding!

-Chad