Friday 4 February 2011

Multiplayer-enabling my Windows Phone 7 game: Day 2–Building a UI with XPF

I’m building a game to enter in Red Gate’s Windows Phone 7 App competition. The first challenge I set myself was to build the core of the game in 3 days from a standing start. Then Red Gate moved the goal posts. So I’ve set myself a new challenge: make the game multi-player in 3 days, using Windows Azure for the server side.  Day 1, was spent getting up to speed with Windows Azure and networking on WP7. Here’s Day 2:

9:00 Decided to take the plunge and go with Red Badger's XPF framework for the UI - what else can I do, if I want to get this thing done in three days? I’m going to need TextBoxes, ListBoxes and the like, and I certainly wouldn’t be able to write them from scratch in the time I have. On Red Badger’s roadmap, there’s no word on a likely release date. I wonder if I can badger them into at least giving me a build that won’t expire before the competition gets judged?

9:43 Got my first "Hello World" screen working using XPF. For ages I couldn't get buttons to respond to clicks, until I noticed from a sample that I needed to supply an InputManager instance to the RootElement.

10:47 Created a TextBox control using XPF. They've done a good job of mimicking the Silverlight API. And in some ways, their DependencyProperty implementation is even better! It uses generics for a start. And the key classes are actually called ReactiveProperty and ReactiveObject because their change notification is based on IObservable from the Rx Framework (which, by the way, comes in the box on WP7). Text input on XNA is pretty limited. Your only option is to call Guide.BeginShowKeyboardInput, which is an async method that takes care of showing the soft keyboard as well as the editor, and then returns to you the text that was entered.

11:40 Refactored my game so it now has Screen classes to represent the states that it can be in - Showing the Game, Showing the Welcome Screen, Showing Help, etc. It’s nice that XNA has the concept of Components and Services built in.

14:21Got a simple dialog working:

clip_image001

14:36 Borrowed the Messenger code from Laurent Bugnion's MVVM Light Toolkit to enable me to pass messages in a loosely coupled way between my screens.

15:06 Seeing strange behaviour in XPF where clicks on a button seem to be handled twice: once by the button, and then by widgets on the following screen (which is made visible by the button click). Realise that this is what comes of changing one screen for another in the middle of handling events. I'm going to have to implement a mini message queue so I can queue the change of screen after the button event has been handled.

15:15 Implemented the message queue, and magically another bug goes away too! That bug was most odd – after I clicked one button, moved to a different screen, then moved back again, all the other buttons would stop working. It turned out that the first button was capturing the mouse events, so the other buttons didn’t get a look in. Making sure that events completed before changing screens obviously fixed the mouse capture problem too.

16:05 Dialogs are coming on nicely now, but it sure is tedious building up a control hierarchy in C#. Oh XAML, how I miss you!

17:21 Got a very basic ListBox working on top of XPF. The time I’ve spent delving around in WPF and Silverlight certainly helps out here!

image

17:30 I think that’s enough of the multi-player UI done for now. That leaves me with one day to implement the multi-player logic, and the server.

Do you think I can do it?

1 comments:

Howard said...

Can he build it?
Yes He Can!

Post a Comment