VS 2010 Windows Phone Refresh

Mars Bar

A student gave me a Mars Bar at the end of my last lecture of the session. It is kind of a running joke thing, in that I keep promising the class Mars Bars and never delivering. Anyhoo, thanks very much. It was delicious.

The  next version of the Windows Phone 7 CTP is now available for download.  This version plays nicely with the release version of Visual Studio 2010. Some folks have been reporting fun and games updating but, for some reason, my update went fine.  The only issue I’ve hit is when opening an old Windows Phone project I was told I needed to add some lines to one of the configuration files. Unfortunately the lines can’t be copied out of the message for some reason, so if you need them you can cut them from here..

<Capabilities>
    <Capability Name="ID_CAP_NETWORKING" />
    <Capability Name="ID_CAP_LOCATION" />
    <Capability Name="ID_CAP_SENSORS" />
    <Capability Name="ID_CAP_MICROPHONE" />
    <Capability Name="ID_CAP_MEDIALIB" />
    <Capability Name="ID_CAP_GAMERSERVICES" />
    <Capability Name="ID_CAP_PHONEDIALER" />
    <Capability Name="ID_CAP_PUSH_NOTIFICATION" />
    <Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
</Capabilities>

TechDays 2010 Portugal Session Resources

TechDays Portugal 2010 My Office

ACA009 Creating Windows Phone Games

Here is the content from my session. Thanks for being a great audience.

The code works on the current version of the CTP for the Windows Phone system. You can download this from here. If you want to use demo 3B to serve out accelerometer information to your phone app make sure that the program is running with Administrator privileges, and that you have modified the URL in the Phone Starlight program to address this host (localhost should just work).

If you want to get started with Windows Phone you can find a list of useful lines (and some FAQ entries) here.

ACA004 Giving Robots Life with the .NET Micro Framework

I left Oscar the robot powered up overnight by mistake. I was very impressed to find that he still had plenty of battery power left this morning. Fortunately nobody had been sending movement commands to him via the secret URL otherwise he could have gone anywhere!

If you want to get hold of a robot and Fez controllers you can go to:

http://www.tinyclr.com/

If you want to get hold of the Web Server board you can go here:

http://devicesolutions.net/Products/Tahoe.aspx

If you want the most powerful Micro Framework board I’ve ever seen you can go here:

http://www.ghielectronics.com/product/125

The Micro framework at Microsoft can be found here. There are links to platform manufacturers and a very useful forum. You can even propose enhancements to the platform.

http://www.microsoft.com/netmf/default.mspx

Windows Phone FAQ

Novotel

I’ve decided to start building up my own little set of Windows Phone resources. I’m going to put down answers that I managed to figure out, so that I can look them up again if I ever need to. You can find my FAQ (it is a bit quiet at the moment, but I’ll add more as I find out more) here:

/windowsphonefaq/

This is all based my trial and plenty of error, I’ve left comments open on all the posts, so if you know different for any of them, feel free to put me right.

Geek Night Files

DevDays 2010 Geek Night Setup
My name in lights…

After the fun and games of Geek Night I’ve now put all the source files and the presentation up.

  • You can find the presentation here.
  • You can find all the sample code here.

There are also some more audience pictures on Flickr. Click on the picture above to find your way to my photostream and take a look. I’m off to find a tram, a train and a plane now…

World’s First Windows Phone Controlled Robot

Oscar Takes a Bow

Oscar, my tiny Micro Framework powered robot has become the other first robot to be controlled by a Windows Phone. Charlie Kindel was kind enough to take part in my demo and give the robot commands during the talk. Thanks for that.

I nearly didn’t make it work though, loading the wrong firmware into a device is never going to end well, but in the end all the components fitted together and a happy ending ensued. I’ll have more pictures, and the slide deck that explains how it all works, along with demo code, tomorrow.

Hardware Setup

This was the setup, you can see Oscar next to my laptop, the Micro Framework board I used as a web host is on the far left.  I also had my own router and WIFI access point so that I could get the phone onto my own private internet…

SoundEffects in Windows Phone Silverlight

Buildings

Silverlight in Windows Phone is a great place to write games. I’m having to pick up a whole bunch of new skills but I reckon that it is well worth the effort. One piece of effort that I’ve had to put in is on playing sounds. It turns out that you use the SoundEffect class from XNA to get the sounds out of your games.

The first step is to add the XNA libraries to your game. Open up the References tab in your project and add the Microsoft.XNA.Framework reference.

Now add a couple of using statements to your program to make the XNA classes easier to get hold of:

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

The sound you want to play has to be added to your project. You don’t use the Content Manager in Silverlight though, as there isn’t one.  Instead you add the item as content. Make sure that the build action for the resource is set to Content. As with old school XNA, a SoundEffect can be wav file. I just dropped a beep file into the root level:

image

You can also see here that I’ve loaded the framework. Now I can load the SoundEffect in my game:

SoundEffect beep =
             SoundEffect.FromStream(TitleContainer.OpenStream("beep.wav"));

The static FromSteam method will fetch the effect from a stream. The TitleContainer object fills in for the Content Manager in XNA. If you want to put your sounds into a folder you can, but you must give the path (separated using the / character)

image

Sounds folder as part of the project

SoundEffect beep =
   
SoundEffect.FromStream(TitleContainer.OpenStream("Sounds/beep.wav"));

Now I can play my beep sound in the usual way:

beep.Play();

This is the boring form of the Play method call. You can also control the volume, pitch and left-right panning of the sound as well:

beep.Play(
    0.5f,   // half volume
    1.00f,   // one octave higher (-1 is 1 octave lower)
    -1.0f); // on the left (+1 is the right)

Actually, I’ve noticed what might be a problem here. The documentation says that the pitch value goes from –1 (one octave lower) to 1 (one octave higher). This used to work fine when I used XNA 3.1.  When I go for pitches greater than 0.6 I get really weird sounds. I’m not sure why this is, but I’m trying to find out.

Windows Phone Accelerometer Support in XNA

Signs

There is no native XNA support for the accelerometer in Windows Phone. It seems to have been moved into a different sensors class. I hope it doesn’t stay there. The accelerometer support in the Zune HD is fantastically easy to use and well in keeping with the other inputs.

I’ve written a tiny wrapper class that implements the accelerometer using the new sensor interface, but I really think this should really be put back into XNA, as event driven stuff really doesn’t sit well with the XNA philosophy of polling:

public class AccelerometerState
{
    public Vector3 Acceleration;

    public AccelerometerState()
    {
    }
}

public class Accelerometer
{
    static Accelerometer()
    {
        AccelerometerSensor.Default.ReadingChanged +=
            new EventHandler<AccelerometerReadingAsyncEventArgs>
                     Default_ReadingChanged);
    }

    static AccelerometerState state = new AccelerometerState();

    static void Default_ReadingChanged(object sender,
                                      AccelerometerReadingAsyncEventArgs e)
    {
        state.Acceleration.X = (float)e.Value.Value.X;
        state.Acceleration.Y = (float)e.Value.Value.Y;
        state.Acceleration.Z = (float)e.Value.Value.Z;
    }

    public static AccelerometerState GetState()
    {
        return state;
    }
}

You need to add the Microsoft.Devices.Sensors library to your References to make this work.

While writing this I tried to use keyboard input to simulate the accelerometer, and I found that there is no XNA keyboard support in the emulator, which is fair enough I suppose (although I’d like it really).

It does really weird things in the debugger though, I got all kinds of strange readings if I tried to find out what keys are pressed at a breakpoint when using the immediate mode window.

Of course, I’ve not been able to try this on  a real device (I wish) but if anyone out there does I’d love to know if it works or not.

Windows Phone Resources

TechnoMart

 

If you want to get started on Windows Phone development I strongly recommend that you take a look at the videos from Mix. They are very well presented and easy to view on your PC. There is even an HD version of each one.

http://live.visitmix.com/MIX10/Sessions/CL01 – a good introduction to Windows phone and why it is the way it is

http://live.visitmix.com/MIX10/Sessions/CL13 – a good overview of the windows phone and how you build and deploy applications

http://live.visitmix.com/MIX10/Sessions/CL16

http://live.visitmix.com/MIX10/Sessions/CL17 – these two sessions give a very good introduction to Silverlight development on the phone

http://live.visitmix.com/MIX10/Sessions/CL21 – how to use XNA to build games

http://live.visitmix.com/MIX10/Sessions/CL18 – a nice in-depth description of how the phone works internally

You can get the SDK for Windows Phone here.

You can get the first six chapters of the new book from Charles Petzold on Windows Phone development here.

The forums for Windows Phone developers (which are very well staffed with knowledgeable Microsoft moderators) are here.

There is now a Programming Guide for Windows Phone on MSDN which you can find here.

I’ve got a new Windows Phone

4435712539

Unfortunately it’s not real. Like many other facets of my life, it exists only within the mind of my computer. However, it does work, and I can write programs for it using the latest version of Visual Studio.

If you want your own Windows Phone 7 Series device you can head over to here to perform a one stop download that gives you all the tools you need, including Silverlight, XNA and the emulator.

If you are feeling rich (or are a student on Dreamspark) you can even signed up for the Developer experience here.

Windows Phone and Twitter

4397631853

I’ve started using Twitter a lot more. Some might even say properly. The thing that has got me into the swing of things is the ongoing buzz surrounding Windows Phone. I’m using the #wp7dev tag to find out what is happening, and following Michael Klucher (@mklucher) and Charlie Kindel (@ckindel) to keep up to speed. It really does feel like being part of a breaking news story, which is great.