Switch On The Code RSS Button - Click to Subscribe
Sep
19

Zune Game Development - Getting Started

Zune IconRemember that Game Studio software Microsoft released a while ago that let anyone develop games for the XBox 360? Believe it or not, they just released 3.0 beta that lets anyone write games for the Zune as well! This tutorial is going go through all of the software needed and then demonstrate how to create a simple 'Hello World' application that will run on your Zune device.

I got to hand it to Microsoft. What other manufacturing willingly (and freely) distributes the frameworks and tools needed to develop applications for their devices? Apple is getting close with the IPhone SDK, but you can't write applications for the Nano or IPod. And as far as consoles are concerned, there's nothing that matches XNA in the Nintendo or Sony camps. WiiWare is getting close, but it's still pretty limited.

1. Download and Install the Software


All right, so let's get started. You're going to need to download and install a few applications before you can even think about programming the Zune.

2. Create a New Zune Game Project


Once you've installed Game Studio 3.0 beta, a new project type will be added to Visual Studio. All you have to do is create a new project and select Zune Game.

New Zune Game Project

When you create the project, Visual Studio is going to go off and generate a lot of code for you - which is good. All we then have to do is add some code where they tell us to.

3. Add a Font


Before we can add any text to the screen, we need a font. Fonts on the Zune are represented by SpriteFont objects and are added to the project's Content using Visual Studio.

Add New Item Menu

Once inside that dialog, you'll want to choose the SpriteFont object.

SpriteFont item

What that actually creates for us is an XML file containing font information. The default file will work just fine and I didn't need to modify it at all.

4. Write Some Code


This is probably the easiest step in the entire tutorial. All that's left to do is simply print the text, "Hello World!", to the screen using the font we just added to the project. The first thing you need to do is locate the Draw function that Visual Studio was nice enough to generate for us. It will be located in Game1.cs and should look something like this:

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">
///    Provides a snapshot of timing values.
/// </param>
protected override void Draw(GameTime gameTime)
{
  graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

  // TODO: Add your drawing code here

  base.Draw(gameTime);
}

This function is called roughly 30 times per second and is where you'll put all of the code to draw things to the screen. Here's how to modify that function to draw some text:

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">
///   Provides a snapshot of timing values.
/// </param>
protected override void Draw(GameTime gameTime)
{
  graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

  // TODO: Add your drawing code here
  spriteBatch.Begin();

  spriteBatch.DrawString(Content.Load<SpriteFont>("myFont"),
    "Hello World!", new Vector2(10, 10), Color.Black);

  spriteBatch.End();

  base.Draw(gameTime);
}

That's it! Three extra lines of code are all that's required to throw text on the Zune's screen. We first call Begin on the SpriteBatch to prepare the graphics device for drawing. We then call DrawString to print some text on the screen. The Content.Load function loads the font we added earlier and returns a SpriteFont object - I named my font "myFont". Normally you would load the font outside of the draw loop into a member variable so it didn't have to do it every time it draws. DrawString also takes the actual text you want to draw, the position, and the color. Lastly, call End to flush the sprite batch.

After you've got that code in there, all you have to do now is hit Run in Visual Studio (F5). After a few seconds of loading, the text should appear on your Zune. Since it doesn't look like Microsoft has emulators (or at least one I could find), here's an actual picture of the output on my Zune.

Zune Hello World Output

Once your game has been deployed to the Zune, it will also be accessible through the Zune's Game menu.

Zune Games Menu

There's no easy way to distribute your Zune apps yet, but I'm sure games and applications will be added to the Zune marketplace shortly - once 3.0 is fully released. In the mean time, you're limited to building your own apps and sharing them with whoever is willing to download and build your source code. Speaking of source code, the Visual Studio 2008 project I created for this tutorial is available for download here.



Posted in Zune, XNA, All Tutorials by The Reddest |

5 Responses

  1. The Fattest Says:

    OK I need to get a Zune now. I hate you.

  2. The Reddest Says:

    Buy it from the Zune website so you get a sweet SOTC or PFP logo engraved on the back :) .

  3. ed_private Says:

    Nice tutorial. Does anyone know of any more tutorials? Especially ones that go into greater detail, maybe one that includes details about putting graphicals to the display.

    Thanks

  4. The Reddest Says:

    As a starter, you can download the source for an example game from Microsoft. It’s not a tutorial, but you can learn a lot from looking over the code.

    In a couple of days I’m going to post another, more in-depth, tutorial that does use graphics. So check back in.

  5. ion Says:

    how do you make a zune game menu for your game

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Powered by WP Hashcash