Zune HD

I’ve just managed to get my hands on a Zune HD. It is a personal music player from Microsoft. The Zune brand has been around for a while. The first players appeared a few years ago and have been developing ever since. They are rather like ipods; but they have one or two nice extra features, including built in WIFI and radio but they have always something of also-rans when compared with the all-conquering Apple product.

However the HD version might change that. It has a superb OLED display and an all new multi-touch user interface. As the name implies, you can put high definition video onto the machine and get video output into an HDMI display.  The whole package is lovely and the hardware is beautifully made and very stylish.

It also runs XNA, so you can take C# games that you have written for the framework and they just run on the device. Your games can even take advantage of the multi-touch interface and the accelerometer inside the Zune. I managed to convert a game to use them in just a few minutes. I’m going to write some posts nest week about porting games over onto the platform, but there won’t be much to say as it is all so easy to use.

The only problem with the Zune is that you can’t get it in the UK yet.

Zune HD is out, and it Supports XNA

Today the new Zune platform is released by Microsoft. Called the Zune HD it looks absolutely wonderful. It has solid state storage, an OLED display and a multi-touch user interface.

And, (and this is the wonderful news) it supports XNA. A set of XNA 3.1 Extensions has also been released which you can use to take your games and run them on this fantastic platform. And the extensions even provide access to the accelerometer and the multi-touch input.

If Microsoft get around to putting a phone in there too they will have their first proper iPhone beater.

The only snag is that for now it is a US only release, but with a bit of luck it will make it to us eventually.

Free XNA Curriculum Materials Now Live

If you have been wondering about what all the “Today I have Been Mostly Writing” posts last month were all about you can find out as the courseware is now available on Microsoft Faculty Connection:

This is a complete programming course which is designed to be taught over 10 weeks at a rate of 6 sessions a week (although you can pull individual sections out and use them if you wish).  There is a course matrix that sets out how to sequence this.

The course teaches programming from first principles, using XNA games as the basis of all the sample code.  There are extensive tutor notes on the slide decks and a sequence of step-through labs for students to follow. There are even revision tests for each section.  It is based on the chapters in my textbook, which is the first link in the above list.

You can download the material without signing in, by selecting the “Skip this Step” option on the download page.

If you are going to use the material in any way I’d love to hear how you got on.

Breaking Changes in XNA 3.1 SoundEffect

I hate breaking changes. They are like getting into your car and finding that the steering wheel is now the gear lever, and the seats are facing the other way.

Generally speaking the people who make the software try to avoid them too, which is as it should be. But every now and then they make the judgement call that somebody else’s pain is worth their gain, and so they go and move the universe around a bit.

They have done it with the move to XNA 3.1 from XNA 3.0. XNA 3.0 introduced a new SoundEffect type which made it much easier to make sound. Unfortunately, in its original incarnation this type also made it easy to inadvertently make sound that stole all the sound channels by mistake, and so they have fixed this in version 3.1.

Essentially, in XNA 3.0 the SoundEffect.Play() method used to return a reference to a SoundEffectInstance object, that you could then tweak to change some of the properties of the playing sound. This was kind of neat, except that if you ignored the return from Play it meant that the SoundEffectInstance that was created ended up being left hanging around, probably hogging a sound channel, until the garbage man got around to killing it off. If your game was well designed and looked after memory properly this may not happen of course, and so you would run out of sound channels for no good reason.

In XNA 3.1 the same Play method returns something different. It just sends back a boolean value that indicates that the sound is playing correctly. To get hold of a SoundEffectInstace you have to call the aptly named CreateInstance method on your SoundEffect. All very sensible, and much less likely to hog all the sound channels.

However, if you have just written a book which carefully describes the way that XNA 3.0 works in this respect (just like I have) then you are left wondering why they didn’t add an extra method (perhaps called QuickPlay or something) and leave the old Play intact…

Oh well.

My New Book is in the shops

A man from UPS dropped of a big box today. In it were 10 copies of my latest book. One of the many nice things about writing for Microsoft Press is that they give you 10 free ones.

I’ve been through the text and not found any mistakes so far, which is rather nice.

Oh, and for the student who won the Super Geek Word search at the Summer Bash, your prize has now arrived……

XNA at DevDays 09

My final session of the trip had me in front of another great audience. Thanks folks. I’ve put the code for all the demonstrations here.

3575955171

This is my setup for the presentation. If you want to find the other pictures you might be in, you can find them on my Flickr pages.

After the talk it was off to grab a taxi to the station and then on to a very nice train (they have very nice trains in Holland) back to the airport and a plane home.

3576762770

I like the seafood bar at Schipol airport. Not that raw fish before a flight strikes me as a massively good idea.

XNA Lerp

I’m going to start blogging things that I find useful, so that I can find them again when I need them. You might find them useful too, with a bit of luck.

Lerp is a new thing in XNA 3.0. It lets you find colours between other colours. You can use it for blending, so that you can create a smooth range of colours from one extreme to another.  It is very easy to use:

Color newColor = Color.Lerp( firstColor, secondColor, amount );

You give it the first colour, the second colour and the amount you want to travel between them, in the range 0-1. If the amount is small (close to 0) you will get mostly first colour. If the amount is large (close to 1) you will get mostly second colour.

I use it to make darker versions of a particular colour, so I can create fake lighting effects:

Color shadowColor = Color.Lerp( objectColor, Color.Black, 0.2f );

This produces a darker version of objectColor. To make it even darker, increase the value 0.2 to a larger one.

You can use this to produce tinting effects too.

Breaking in With Thirteen One Magazine

I met up today with Craig from Thirteen 1 magazine. They are doing a set of articles on breaking into the games industry, and I’m going to be recording some video podcasts for them about learning XNA.

Don’t worry, the camera won’t be pointed at me. Instead I’m going to capture the steps you need to follow to set up your computer and then write some XNA games. Should be fun.

XNA Networking and Hair Tearing

Today is the day I’m supposed to write all about how to create networked XNA programs. This is a wonderful feature of the platform, and makes it really easy to make multiplayer games for PC, Xbox or even Zune. Or at least it would be, if I could get the networking to work.

I’ve got the material written but my programs just don’t notice each other. They just sit there, aloof and out of touch. I was a bit cross about this for a while, but then I tried some sample programs from other sources and they don’t work either. I think it must be something about the installation I have here, but at the moment I’m not sure what.

The good news is that the Zune devices which I’ve got, which also support network gameplay via XNA, work just fine.

X48 Cheesy Success

Last weekend four of our students went over to Derby to take part in the X48 Marathon gamecamp.  The idea was to create a game from scratch using C# and XNA 3.0 based on a particular theme. So it was that Harry Overs, Rob Eagle, Rob Hubbucks and Craig Dickman from our second year headed over to Derby to rub shoulders with lots of fellow game developers, many of whom were students from Masters levels courses.

Our lowly second years actually did quite well for themselves. The theme was “evolution” and by the simple technique of not sleeping for a day and a half they managed to come up with “Evo Fighter” a beat-em-up that merges arcade punching action with an exposition of the ideas of Darwin.

3387283316

Part of the very funny start screen….

3386470827

Evo Fighting Action

This managed to walk off with the “Cheesiest Game Award”. When the cheese arrives from Derby, I’ll put up a picture of the team with their prize. I’m very proud of them, and like to think I have taught them well. You can find out more about them here.

Apparently Channel 4 were there filming, so there might be some TV coverage too.

I’m hoping that the competition will become an annual event. I’m tempted to dress up as a student (some say I already do) so that I can take part if it runs again. Many thanks to everyone at Derby, Microsoft and Pixel-Lab for setting it up.

Converting Windows Bitmaps to XNA

If you have ever wondered how to convert Windows Bitmaps into XNA textures then wonder no more. This method will do it for you. It is not particularly elegant (or fast) but it will let you take images off your PC (or the web) and put them into textures for use in XNA programs. Note that this will only work on XNA programs that are running on a Windows PC, the Xbox is not allowed to do this kind of thing at all. You need to add a reference to System.Drawing to your project and use the System.Drawing namespace.

Some of the code is a bit messy because of namespace clashes, and I'm sure there is a neater way of doing this. But it does work.

private Texture2D XNATextureFromBitmap(
              
System.Drawing.Bitmap b, GraphicsDevice device)
{
    Texture2D xnaTexture =
               new Texture2D(device, b.Width, b.Height);

    Microsoft.Xna.Framework.Graphics.Color[] dots =
         new Microsoft.Xna.Framework.Graphics.Color
                                           [b.Width * b.Height];

    int x;
    int y;
    int pos = 0;

    for (y = 0; y < b.Height; y++)
    {
        for (x = 0; x < b.Width; x++)
        {
            System.Drawing.Color sourceColor = b.GetPixel(x, y);
            dots[pos].A = 0xff;
            dots[pos].R = sourceColor.R;
            dots[pos].G = sourceColor.G;
            dots[pos].B = sourceColor.B;
            pos++;
        }
    }

    xnaTexture.
           SetData<Microsoft.Xna.Framework.Graphics.Color>(dots);

    return xnaTexture;
}

.NET Micro Framework 3.0 is Now Out

While we are talking about Version 3.0 of stuff we find that the third version of the .NET Micro Framework is also available. This one is very interesting, because it with it the mouthwatering prospect of being able to develop for the embedded platform using the Express versions of Visual Studio. It runs in Visual Studio 2008, including the free ones. This is wonderful news for hobbyists, as it means that you just need to get some hardware and you are away writing C# code for your tiny device. Go and get it (again for free) here.

And don't forget to enter the DareToDreamDifferent contest.

Zune Power

I've been playing with XNA on Zune, porting a little sprite toolikt from StarLight onto it. For those of you who haven't played with the Zune, it is basically an ipod that you can run XNA on. I managed to get 400 sprites with transparency bouncing around quite happily. I'll post the code on VerySillyGames when I've finished, but this means that you can get quite complex displays on the tiny platform with no problems at all.

Good XNA Stuff to Cheer You Up

In the midst of hardware despair it is always nice to reflect on the good things in life. Like what Mike Smith has been doing down at the Prospect School in Reading. He has got some of his Year 10 writing XNA. That's 14 year old students writing and running C# games. Wonderful.  By all accounts he has been having great fun, and even made the papers. You can find out even more from Paolo here. The students are even blogging about their experiences here and here.

When we were in Paris we saw some high school students who had entered the embedded challenge and made it to the world finals. I think those folks were 16 or so, which means that you've got a couple of years start......

I'm all cheered up now. I think I'll go to bed.

Loading Web Pages

I don't usually put up techie pages with code in them, but today I present something that I think might be useful and I've not found anywhere else. It is part of my RSS reader for the XNA display program, and it solves a couple of problems that you might hit. My feed reader needs to read feeds that are on a password protected site, and it also needs to read feeds that are compressed. This method does both:

private StringBuilder readWebPage(
    string url,
    string username,
    string password,
    string domain)
{
    // used to build entire input
    StringBuilder sb = new StringBuilder();

    // used on each read operation
    byte[] buf = new byte[8192];

    try
    {
        // prepare the web page we will be asking for
        HttpWebRequest request = 
            (HttpWebRequest)WebRequest.Create(url);

        if (username.Length > 0)
        {
            request.Proxy = null;
            NetworkCredential credential = 
               new NetworkCredential(username,
                                     password,
                                     domain);
            request.Credentials = credential;
        }

        // execute the request
        HttpWebResponse response =
            (HttpWebResponse)request.GetResponse();

        // we will read data via the response stream
        Stream resStream;
        Stream inputStream =
            response.GetResponseStream();

        // Might have a compressed stream coming back

        switch (response.ContentEncoding)
        {
            case "gzip":
                resStream =
                   new GZipStream(inputStream, 
                          CompressionMode.Decompress);
                break;
            case "":
                resStream = inputStream;
                break;
            default :
                debugOutput.PutMessageLine(
                    "Invalid content encoding: " +
                    response.ContentEncoding + " in: "
                    + url);
                return null;
        }

        string tempString = null;
        int count = 0;

        do
        {
            // fill the buffer with data
            count = resStream.Read(buf, 0, buf.Length);

            // make sure we read some data
            if (count != 0)
            {
              // translate from bytes to ASCII text
              tempString = 
                Encoding.ASCII.GetString(buf,0,count);

              // continue building the string
              sb.Append(tempString);
            }
        }
        while (count > 0); // any more data to read?

        return sb;
    }
    catch (System.Net.WebException w)
    {
        debugOutput.PutMessageLine(w.Message);
        return null;
    }
    catch (System.Net.ProtocolViolationException p)
    {
        debugOutput.PutMessageLine(p.Message);
        return null;
    }
    catch (Exception e)
    {
        debugOutput.PutMessageLine(e.Message);
        return null;
    }
}

This is not very elegant code, but it does work. I've pulled it straight out of the program and so there are a few things you need to know. I have a class called debugOutput which I use to send messages to the user. You either need to create one of your own, or remove those lines. If you need to use a username and password you need to add those to the call, otherwise you can leave those fields as empty strings.