FGF: Getting Started

This series is devoted to the design and development of my framework, FGF (Focused Games Framework), and aims to cover topics like async content management, WCF services, and many more. In this first article, I cover how to setup Visual Studio 2008 for coding the framework. It is important to understand that I will be using Visual Studio Team System 2008 and thus may have features that are not available in the Express edition. It is possible to get around many of these or ignore them completely, however, so not having Team System does not mean developing FGF is impossible.

The first step is to open up the IDE and create our solution. When starting a large solution such as the one for FGF, I find it useful to create a Blank Solution so that the solution’s name can be different than that of the first project. Again, this can be worked around in Express as well as other versions of the editor.

Blank FGF Solution

Continue reading

2D Fog Of War

This content may move. Please update your bookmark to point to http://vdir.us/go/2d-fog-of-war

Fog Of War Sample

This tutorial covers a basic way of implementing two dimensional fog of war for a game in XNA and assumes you (the reader) has basic knowledge of C# and the XNA Framework. To get things started, create an empty Windows game project. Two textures will be needed: one for the Light and one for the Background. After adding these to the Content Project, go ahead and add the following members to the game class.

Texture2D lightTexture;
Texture2D backgroundTexture;

RenderTarget2D lightTarget;
RenderTarget2D mainTarget;

Effect basicFogOfWarEffect;

While the use of the texture fields is obvious, the use of the render targets may not. The concept behind this fog of war implementation is to draw the light texture to the lightTarget render target and then use the produced texture as the alpha channel for the texture produced from the mainTarget render target.

Continue reading

Zune HD: Calling GetState Twice

Beware that when you call TouchPanel.GetState twice within the game loop, what touch locations had a Pressed state the first time will have a Moved state the second time. Consider the following lines of code.

TouchCollection touches = TouchPanel.GetState();

foreach (TouchLocation locale in touches)
{
    if (locale.State == TouchLocationState.Released && locale.Id == id1)
        id1 = -1;
    else if (locale.State == TouchLocationState.Pressed && id1 == -1)
        id1 = locale.Id;
    else if (locale.Id == id1)
        pos1 = locale.Position;
}

touches = TouchPanel.GetState();

foreach (TouchLocation locale in touches)
{
    // Can fail if the first time through it was Pressed.
    if (locale.Id == id1 && locale.State == TouchLocationState.Pressed)
    {
        // Do something important
    }
}

Note that it isn’t important that these are in the same file let alone the same method. You cannot rely on having access to the same state data everytime you call GetState within the game’s loop. So it will probably become important to put the touch code in a global location and store the states for the duration of the loop. For instance you can store the TouchCollection data in a static variable at the top of the Game’s Update method.

How To: Zune HD Touch Testing

Touch Testing on Zune HD

One of the first “games” I made for the Zune HD was a simple little application to test how accurate and quick the touch panel is. This How To gives you the code to get started with your own basic testing application.

After creating a Zune game with XNA 3.1, the first thing you need to do is define a basic particle struct to hold some data that we track as the user touches the screen. Specifically we need to track whether or not a particle is active (do we update it and draw it?), its position and its life (how long it has been there). I created this structure within the Game1 class but really it can go anywhere.

Continue reading

The Music Marketplace Sucks

While some will say that the CD-ROM is not a long term medium for the storage of audio tracks, I believe that it is. Just the other day I popped in a Weird Al CD from ages ago (The Food Album) and it worked flawlessly despite a couple of scratches. No DRM, no licensing, no restrictions of any kind. I paid for the CD once and have (virtually) unlimited ability to listen to the songs.

This probably doesn’t shock you, and it shouldn’t because most of the world purchases music in CD form, or has at some point. The point is to remind you of how nice things were when the CD was the powerhouse. Now that virtual marketplaces have cropped up all over the place (iTunes, Zune, Napster, Walmart, Buy.com, Amazon, et al) people are jumping on board without first thinking about the problems. What happens when a store shuts down? What happens when an artist stops selling their work on the marketplace? For many this will spell doom: I bought an album by CCR on the Zune marketplace and within a month I had no license to play the songs because the tracks weren’t available for sale anymore. Wait, what? That’s right – they weren’t selling something that I already bought so I couldn’t use it. Could you imagine if your car went *poof* and disappeared when the newer model came out?

Similarly, I recently installed Windows 7 RTM and was redownloading my purchased music from the Zune marketplace when I noticed that some were erroring out. The reason? Apparently I had downloaded some of the songs too many times! But don’t get to thinking that the Zune marketplace is the only one with problems like this. The iTunes for a long time had DRM songs which immediately brings any problems associated with DRM. Just ask anyone who bought DRM songs from Walmart only to be asked to back them up when the DRM servers were shutdown.

So what is the solution? Sadly there isn’t one, although the Walmart choice doesn’t seem too bad. If you have burning rights on your downloaded tracks, burn them so you can rip them back at a later date if need be. But this begs the question, why by from a virtual marketplace if you need the physical CD?

Cross Platform XNA Projects (X64 Content)

One of the requirements of the framework I am building (FGF) is cross platform support. For my XNA games this means support for not only Windows but also the Zune and the Xbox 360. For my Windows based projects I often find that X64 can be used (and in the case of IIS in 2008 R2, encouraged) so I also support X64 versions.

The problem is that when using an XNA project template to build a library for the simple fact that XNA projects can automatically synchronized (across platforms), Visual Studio blocks the creation of an X64 build target. Rather you are stuck with X86, Zune or Xbox 360.

The good news is that you can get around this! Open up the Windows project file (csproj) in a suitable text editor and copy the sections for both “Debug|x86″ and “Release|x86″ and paste them right after.


  true
  full
  false
  ..\Bin\x86\Debug\
  DEBUG;TRACE;WINDOWS
  prompt
  4
  true
  false
  x86
  false


  pdbonly
  true
  ..\Bin\x86\Release\
  TRACE;WINDOWS
  prompt
  4
  true
  false
  x86
  true

Next you simply replace the instances of x86 with x64 and change anything else you need.


  true
  full
  false
  ..\Bin\x64\Debug\
  DEBUG;TRACE;WINDOWS
  prompt
  4
  true
  false
  x64
  false


  pdbonly
  true
  ..\Bin\x64\Release\
  TRACE;WINDOWS
  prompt
  4
  true
  false
  x64
  true

One warning – this should only be used for projects that don’t require references to the XNA framework. At this time Microsoft has no support for x64 XNA references.

Important .NET 4.0 News

Scott “Gu” (Guthrie) has started a series of posts about VS2010 and (more importantly) .NET 4.0, touting its new features that so far have been incredibly important for developers. It seems that Microsoft is finally “getting it” and listening to us about certain things.

While most of you have already heard about the ability to define Debug and Release web.config files, these two new features may put you over the edge in waiting for .NET 4.0 to release.

  • Clean Web.Config Files

    Finally Microsoft has realized that while having configuration files that are verbose enough to support wild customizations, most of us do not need to change the default sections in the web.config file. So it should come as no surprise that clean configuration files will now be a thing of the (recent) past. It is just a shame it took so long to get.

  • Control over Client Ids

    Hidden in this post about new project templates and what looks to be the ASP.NET WebForms version of the ASP.NET MVC template is a bit about client ids for controls.

    All of the styles and content within the site are configured using CSS, and take advantage of some of the new features with Web Forms in ASP.NET 4 – including clean client-side “id” names (no more ctrl_ mangled names – ASP.NET 4 gives you complete control over the client id), and CSS based rendering instead of table based rendering for the built-in server controls.

    This, again, should come as no surprise as the mangled names can present problems for developers looking to write some quick javascript as well as those looking to simply clean up their HTML. Here’s to hoping that Microsoft cleans up its HTML in other places as well (SharePoint anyone?).

IIS For Dummies: Allowing Anonymous Access!

Pro-tip for today: When attempting to create a website (I am using ASP.NET MVC 1.0) with IIS7 that allows anonymous users under an Active Directory domain it is imperative that you remember to give anonymous users read rights to the web directory on the system’s physical file system. Otherwise you could end up with pages that do not load the CSS correctly.

Furthermore, if you are running into assembly load problems when running on Windows Server 2008 R2 remember that everything is running in X64 and that you need to enable 32-bit compatibility in your Application Pools. To do this select the App Pool and click “Advanced Settings” and set “Enable 32-Bit Applications” to true.

Developers May Become Liable?

By way of a Twitter post1, developers may become liable for damages caused by known bugs in released software. This is an issue that all developers need to pay attention to because it has a very broad range of implications for the industry. Could you imagine if NVIDIA, Apple or Microsoft were required to not only disclose all bugs in each build but also to close them before a release was possible? What time was spent on Vista could double or triple easily with this law. What about developers who focus on XBLIG and/or iPhone Apps? These small (one person) teams are in dangerous waters now and could face suits that they cannot financially defend.

While I agree developers should not be held responsible for serious damages (can a buggy driver burn down your house?), tying down the industry and its workhorse (developers) is not the way to go.

Notes:

1: @nuvm RT @a_williams: RT @cwoodruff: RT @atomicobject: Developers to be held accountable for shipping buggy software: http://bit.ly/Yhax3