Chapter 1. Windows Phone and .NET

It is a genuine pleasure to develop software for Windows Phone 7 devices using Visual Studio .NET.

Microsoft's latest version of its mobile operating system provides a very different environment from the versions that came before it. Virtually everything about Windows Phone is new to the mobile platform: it includes an entirely redesigned user interface, implements the powerful XNA audio/visual libraries for high-performance gaming, and has standard high-specification hardware requirements that all devices are obliged to meet.

There is one key element of Windows Phone that has stayed essentially the same as the platforms that preceded it: the use of the .NET programming environment to create games and applications. This brings with it some exceedingly powerful and flexible programming languages and one of the best development environments available anywhere.

The development platform for Microsoft's mobile devices has advanced substantially over the last decade. During the early years of the original Windows Mobile/Pocket PC operating system, programming involved using the suite of eMbedded Visual tools. They came supporting two different languages: eMbedded Visual Basic and eMbedded Visual C++.

eMbedded Visual Basic was based on the same technologies as Visual Basic for Applications (VBA). It was similar in a number of ways to Visual Basic 6 (VB6), the desktop version of VB that was current at the time, but had many shortcomings, such as the lack of strongly typed variables and poor object orientation features. Programs were written using a stand-alone integrated development environment (IDE), which had its own peculiarities and different ways of working than VB6.

eMbedded Visual C++ presented more of a challenge because of differences not only in the IDE but also in the code. Although established C++ programmers would no doubt have managed to pick up this language without too many problems, those who were less well versed in the intricacies of C++ might have found the amount of new information they needed to learn a significant barrier to entry.

All this changed with the release of Visual Studio .NET and the .NET Compact Framework (.NET CF). .NET CF provides a set of class libraries that are parallel to the desktop .NET Framework. The libraries are not identical because parts of the full .NET Framework functionality are missing from .NET CF. However, a substantial set of identical functionality does exist, and any programmer who is comfortable developing C# or VB .NET applications for Windows will be instantly at home developing against .NET CF, too.

Windows Phone development uses the very latest Visual Studio 2010. The IDE has made advances in a number of ways since that of the earlier versions of Visual Studio, but best of all, Microsoft has chosen to release an "Express" version of Visual Studio that supports Windows Phone development completely free of charge. Although there are charges and fees involved in some areas of development and in distribution of finished applications (as we will see later in this book when we discuss this subject in more detail), these are generally fairly modest and do not create the barriers to entry that having to purchase the full versions of Visual Studio presented in the past.

The Windows Phone development environment also integrates into the full versions of Visual Studio seamlessly if you have such a version already installed.

On Windows Phone devices, all applications are written using managed .NET code. The Silverlight and XNA runtime libraries are preinstalled on the device, so no awkward installation is required of your end users. Finished games and applications are distributed through a central Marketplace operated by Microsoft, which has support for useful features such as update notifications, trial versions, and protection against piracy.

A major advantage of developing for Windows Phone using Visual Studio .NET is that the exact same IDE is used as for desktop Windows development. There is no need to learn the details or keyboard shortcuts of a new IDE; instead, you will be working within the environment you are already used to, which includes all your user interface tweaks and preferences changes. Developing an application for Windows Phone is simply a question of creating a different project type.

Programming within Visual Studio .NET also means that the Windows Phone developer can take advantage of the maturity of the Visual Studio.NET development environment. Microsoft has spent many years improving the user interfaces and functionality of Visual Studio, and countless versions and releases have cumulated in an extremely powerful and user-friendly studio for application design, development, and debugging. All this is at your disposal when developing Windows Phone games and applications.

The Framework also retains much of the power of its desktop cousin, including extensive object orientation features, strong variable typing, generics, flexible collections, and powerful XML processing functions.

Finally, the use of .NET, Silverlight, and XNA means that there are great opportunities for cross-platform development with only a small amount of additional effort. Silverlight games can be modified to run in the browser on a desktop PC, and XNA games can be made to run on a PC or Xbox 360 in addition to the phone.

In this chapter, we will take a closer look at the .NET Framework, at setting up and using Visual Studio, and at creating your first simple Windows Phone application. We will also examine some of the options that are available for game development.

Looking Closely at Visual Studio Development for Windows Phone

Let's start by taking a look at the versions of Visual Studio that we can use for developing software for Windows Phone.

We can develop either using Visual Studio 2010 Express for Windows Phone, which is available free of charge, or by using one of the full versions of Visual Studio. Both products will produce the same resulting games and applications. Visual Studio 2010 has system requirements that necessitate a reasonably modern PC, running either Windows Vista with Service Pack 2 or Windows 7. Both x86 and x64 versions of the operating system can be used, but the Starter Editions of Windows are not supported. A DirectX 10 or later graphics card with a WDDM 1.1 driver is required for developing games using XNA. In practice, this requirement will be met by most graphics cards from the last couple of years, although many mobile graphics chips present in laptop computers might lack these capabilities.

There is no support for developing for Windows Phone in earlier versions of Visual Studio. The good news is that Visual Studio 2010 will install side by side with earlier versions of Visual Studio without causing any problems, so if you need to keep Visual Studio 2005 or 2008 on your PC, you can.

Language Choices

.NET development offers the choice of a number of different languages including C#, VB, and C++. Currently, however, only C# is supported for Windows Phone development. Microsoft is promising support for VB in the near future, so check the latest version of the development environment if you want to use VB for your development.

If you are already familiar with VB, you should find that both reading and writing C# will come naturally with a little practice. In this book we will focus on C# for all of our samples and example code.

IDE Features

As would be expected from Visual Studio, a number of very useful features are available to help develop and debug Windows Phone applications.

Emulators

Visual Studio offers a Windows Phone emulator to help test and debug your programs. Although it is essential to use a real device regularly during your application development process to ensure that everything works properly on actual hardware, being able to use the emulator for general coding and testing is extremely useful. A screenshot of the Windows Phone emulator is shown in Figure 1-1.

Windows Phone emulator

Figure 1.1. Windows Phone emulator

The emulator offers a full implementation of the physical device and is capable of running genuine Windows Phone applications. It offers access to a number of features of the device, including the ability to simulate networking, screen rotation, and touch screen input using the mouse cursor. (In fact, if you are developing on a Windows 7 computer with a touch-enabled screen, you can perform touch and multitouch operations on the emulator by touching your PC screen.)

Running your application in an emulator is as simple as can be: just select to use the emulator within the Visual Studio IDE and start your application. The emulator will appear, and your program will run.

When we fire up the emulator shortly, note that it takes a little while to initialize itself. This would get frustrating very quickly when you are in a repeat modify/compile/test cycle, but the emulator can be left running in the background when you stop your code from executing and will then resume much more quickly the next time you begin a debug session. When the emulator's Close button is clicked, it will prompt for confirmation that the emulator is really no longer required, which is very useful protection against accidentally closing the window without actually meaning to.

Silverlight Page Designer

A fully featured page designer is available to lay out windows and controls for use within Silverlight programs. The designer goes as far as to display an image of the device around the edge of your page to help visualize its appearance.

Silverlight pages can be created and modified by either using the designer or by editing the underlying eXtensible Application Markup Language (XAML, which is generally pronounced "zammal"). We will look at XAML and the Silverlight page designer in a great deal more detail later in this book. Visual Studio will display both the designer and the XAML editor as side-by-side panels within the IDE, as shown in Figure 1-2, and any change made to either will be immediately reflected in the corresponding panel. This provides a very flexible mechanism for page design, allowing each panel to work together to perform their actions more efficiently.

The Silverlight page editor showing the designer and page source together

Figure 1.2. The Silverlight page editor showing the designer and page source together

Breakpoints

Another extremely useful tool is Visual Studio's breakpoint feature. No doubt familiar to any desktop developer, breakpoints are fully supported for Windows Phone development, too, and can be used both when running against the emulator and against a physical device. It can be extremely useful to break into your code, examine your variables, and step through the instructions while watching the results on a real device on the desk next to you.

Debug Output

Access to the Visual Studio Output window is available from Windows Phone applications running inside the IDE. Text can be written to the Output window at any time, allowing you to easily keep track of what your program is doing. Pairing this with the ability to have two independent screens (your PC screen and your mobile device screen) makes this tool particularly powerful.

Windows Phone Platform

One of the major changes that Microsoft has made for Windows Phone, as compared with the previous Windows Mobile platform, concerns hardware requirements.

The huge diversity of hardware could provide quite a barrier for entry for Windows Mobile. Devices all had different screen resolutions, different hardware buttons, and a fairly substantial range of other internal hardware. Writing games and applications that worked across the entire set of devices could result in a considerable amount of additional effort, whereas saving time by not addressing all these platforms could exclude a significant proportion of the potential customer base from being able to use the application.

This has been tackled head on in Windows Phone by requiring a very rigid set of hardware requirements. It will be interesting to see how they evolve as time passes and technology evolves, but for the time being you can depend upon this hardware platform being present in all Windows Phone devices.

Let's take a look at what we can expect.

Screen Hardware

To begin with, all Windows Phone devices will have a screen with a Wide VGA (WVGA) resolution (480 pixels across by 800 pixels tall), which will greatly simplify the task of ensuring that games and applications properly fit on the screen without having to stretch, shrink, or leave large areas of the screen unused.

Microsoft has stated that future devices might use a Half VGA (HVGA) resolution of 480 pixels by 320 pixels, but at the time of writing no such devices have been announced.

All Windows Phone7 devices will have capacitive touch screens. Capacitive screens tend to be much more durable than the resistive screens used in many older devices and tend to be more sensitive. They also offer support for multitouch input, which is generally not available on resistive devices. The main disadvantage of capacitive screens is that they require interaction from a conductive source (such as a finger) and they don't work with a stylus (although special capacitive styluses are available if you hunt around). The design of the Windows Phone operating system is based around touch input rather than stylus input, a decision that is consistent with most smartphone platforms and operating systems currently in production.

Windows Phone devices will support multitouch, with a minimum of four distinct points able to be tracked at once. This opens up some interesting possibilities for gaming, and we'll be looking at how to use multitouch in games later on in this book.

An important consideration when designing a game for a mobile platform is that the screen orientation can be rotated when compared to that of a desktop PC, resulting in a screen that is tall rather than wide. This benefits some types of games (Tetris-style games, for example), but can be problematic for others. Fortunately, Windows Phone 7 has extremely good support for rotating into landscape orientations, so you can take advantage of whichever screen layout best suits your game.

Hardware Buttons

One of the details that Microsoft has been very strict about for devices running its new operating system is hardware buttons. All devices must have exactly three buttons on the front of the device: a Back button, a Windows button, and a Search button.

Having consistency over the available buttons is good for developers as it means that we don't have to worry about lots of combinations of control mechanisms. However, this limited set of buttons means that there will be no directional pad available, which is a pity because they are very useful as a game input device.

Instead we can use the touch screen for input, and there are lots of clever and creative ways that this can be done, from designing games that the user interacts with by touching objects on the screen to displaying movement buttons at the bottom of the screen for the user to press.

These rigid requirements don't rule out the possibility of a device manufacturer including a hardware keyboard with the device, however, and this is likely to be a common feature among Windows Phone 7 devices. Keyboards can be implemented either as a slide-out panel behind the screen or below the screen in a similar style to BlackBerry devices. The presence of a keyboard opens up the opportunities for the player to control your game, but in most cases it would be sensible to avoid making this a necessity for your game to avoid excluding a large proportion of your audience.

Processors

The Windows Phone 7 platform specification states that all devices must be equipped with at least a 1GHz processor. This should result in excellent performance across all devices.

You should expect processor speeds to increase as the platform evolves, so it is important to cater for devices that are running at faster speeds than this, but as a minimum it does mean that a significant amount of processing power will be available on all devices.

Graphics Hardware

One of the problems that developers on the Windows Mobile platform faced was in the choice of a graphics application programming interface (API). It was uncommon for Windows Mobile devices to have hardware acceleration, which meant that the only graphics API available across all devices was the Graphics Device Interface (GDI), which was very lacking both in terms of features and performance.

This problem can be put firmly in the past with Windows Phone. The graphics API for high-performance games is XNA, a powerful library based around the DirectX technology that has been powering desktop PC games for the last decade. The phone implementation isn't quite as powerful as on the desktop, but it still has very impressive capabilities for a mobile device.

Alongside the API is hardware graphics acceleration, which the phone needs to create fast-moving, complex two-dimensional and three-dimensional scenes without bringing the device to its knees. Because it will be included as standard in all devices, the opportunities for gaming are immense.

Location and Orientation

Also standard on all devices will be an accelerometer and a Global Positioning System (GPS) receiver.

The accelerometer can be very useful for game developers. It allows the device to detect which way up it is being held and can sense in detail any movement that results in the device being rotated. This provides an excellent input control mechanism, allowing players to influence what is happening on the screen by physically moving their phones.

Probably of less interest for gaming is the GPS functionality. When appropriate line-of-sight reception has been established with the GPS satellites, the device can detect where in the world it is located. This opens opportunities for making games that revolve around the player's whereabouts, but the scope for this in gaming is likely to be limited.

Cooperation with the Device

Let's not forget an extremely important fact: your game is running on other people's phones and personal organizers. They will place more importance on tasks such as answering a phone call or responding to a calendar reminder alert than in continuing to play your game.

Running applications have limited control over what happens when other features of the device become active. An application that loses focus will be closed down, regardless of whether the user was finished with it.

These terminated applications can be resumed at a later time, and the operating system will indicate that they are being relaunched rather than restarted from scratch. To ensure that users don't lose their progress in a game, we can take care to behave nicely under these conditions: we can save the game state to the device prior to exiting so that it can be automatically restored the next time the game starts and automatically pause when the game resumes to allow the user time to adjust to what is going on. People will appreciate details like these.

This kind of feature often becomes invisible when it works well but is much more likely to be very visible when it doesn't work. Make sure that you take these unexpected interactions into consideration.

Using Visual Studio for Windows Phone Development

Let's take a look now at the steps required to begin development of Windows Phone games and applications.

Installing Visual Studio

Installing Visual Studio for Windows Phone development is very easy. If you do not already have a full version of Visual Studio installed, you can visit http://create.msdn.com to download Visual Studio 2010 Express for Windows Phone. This is a free, complete, and fully functional development environment that will provide all the tools needed for you to develop your games.

If you already have a full version of Visual Studio 2010 installed, the same download will allow you to add support for Windows Phone projects to your existing installation. The setup application will detect the presence of Visual Studio 2010 when it is launched, and will download just the components that are required, based on your current system configuration.

Once the installation is complete, Visual Studio 2010 can be launched, and the new project types for Windows Phone development will appear. Figure 1-3 shows the New Project window from Visual Studio 2010 Express for Windows Phone, containing just the Silverlight and XNA project template.

Creating a new project in Visual Studio 2010 Express for Windows Phone

Figure 1.3. Creating a new project in Visual Studio 2010 Express for Windows Phone

Figure 1-4 shows the same window in Visual Studio 2010 Professional with the Windows Phone development tools installed.

Creating a new project in Visual Studio 2010 Professional

Figure 1.4. Creating a new project in Visual Studio 2010 Professional

Once everything is installed as required, we are ready to begin.

Creating a Windows Phone Project

With tools all in place, it is time to finally create a simple Windows Phone application and take a look at how we interact with both the emulators and real devices. We will create a simple Silverlight application for this purpose.

To begin, select File

Creating a Windows Phone Project

Above the templates is a drop-down list that allows the .NET Framework version to be selected. For Windows Phone development we will always leave this set to .NET Framework 4.

At the bottom of the window, select a project directory and enter a project name (or accept the default name of WindowsPhoneApplication1 if you wish). Unless you have a particular preference for using separate directories for the solution and project files, uncheck the Create directory for solution check box to keep the directory structure a little tidier.

Once everything is ready, click the OK button to create the project. After a few seconds, the new project will open within the Visual Studio IDE.

Project Templates

A number of different templates are provided by Visual Studio for your new project. Each of these will result in a different initial project for you to start working on, as follows:

  • Silverlight/Windows Phone Application: This is the main project template for creating Silverlight applications. When we build games using Silverlight later in this book, this is the template we will use to create them.

  • Silverlight/Windows Phone List Application: This template creates another nearempty Silverlight project, but with a scrollable item list initially present within the main page. This can be a useful shortcut if your user interface takes this form.

  • Silverlight/Windows Phone Class Library: In order to create a class library that can be used by other Silverlight projects, use this template. Note that Silverlight class libraries cannot be used by XNA projects.

  • XNA Game Studio 4.0/Windows Phone Game: This is the template to select to create a new XNA game project. We will use this template when we begin creating our first XNA projects in Chapter 2.

  • XNA Game Studio 4.0/Windows Phone Game Library: Just as with the corresponding Silverlight template, this template creates a class library that can be used by other XNA projects. XNA class libraries cannot be used by Silverlight projects.

It is not possible to change the project type once the project has been created. If you find that you need to change the project once you have started developing it, you will need to create a new project of the required type and copy in all of the existing code files.

Designing a Page

Now, we are ready to make some minor changes to your test application's default page. The page is named MainPage.xaml inside Solution Explorer and should open automatically when the project is created.

On the left half of the page editor window is the page designer and preview area. On the right half is the XAML code for the page. If you want, you can change the orientation of the divide by clicking the Horizontal Split or Vertical Split buttons at the bottom or right of the dividing bar between the two. The two parts can also be quickly swapped over by clicking the Swap Panes button, also located inside the divider. The designer panel also contains a useful zoom slider that allows you to focus more closely on the page design for detailed layout work if required.

Notice that the page is very, well, black. There is actually a good reason for this, and it is something that you'll notice across many of the Windows Phone applications. Windows Phone devices commonly use organic light emitting diode (OLED) screens for display; they provide a sharp image and are highly responsive to updates, but consume more power when they emit more light. Having a black background therefore results in lower power consumption, which is always a good thing for a mobile device.

For the purposes of this simple application, we will simply place a Button control onto the page and get it to display a message when clicked. The Button is added from the toolbox exactly as it would be for a desktop application: click the Button icon in the Toolbox panel and then draw it into the empty region in the center area of the page. The result can be seen in Figure 1-5.

Windows Phone Silverlight page designer

Figure 1.5. Windows Phone Silverlight page designer

Once you have added your Button, take a look at its properties in the Properties window (see Figure 1-6). If you are used to creating Silverlight applications outside of the Windows Phone environment, everything should look very familiar: all the normal Silverlight properties should be present and correct. If you have worked only with Windows Forms in the past, many of these properties might be unfamiliar, but there should also be some whose purpose is obvious. Once again, we'll look into many of these properties in much greater detail in the Silverlight chapters later in this book.

The Button's properties

Figure 1.6. The Button's properties

Tip

If the Properties window is not open, it can be opened by selecting the View/Properties Window item from Visual Studio's main menus. Under the default key mappings, it can also be opened by pressing F4 on the keyboard.

Double-click the button to open the code designer and create the button's Click event handler. This will display the "code behind" file for the page, which is where the C# code is developed. In Solution Explorer you will see that the MainPage.xaml item has expanded to reveal MainPage.xaml.cs contained within. These two files are analogous to the form design and form code files that are present when working with Windows Forms.

The code within MainPage.xaml.cs should look just as you would expect when developing a desktop application. At this stage, it should be clear how much similarity there is within the Visual Studio IDE between desktop and Windows Phone application development.

Complete the implementation of the button1_Click procedure, as shown in Listing 1-1, so that it simply displays a MessageBox.

Example 1.1. The button1_Click procedure

private void button1_Click(object sender, RoutedEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("Debug text");
}

Running the Application

We are now ready to compile and run the project. Press F5 to begin the process. After compilation (and assuming that there are no errors!), Visual Studio launches the emulator. As mentioned earlier, this can take a little while to open, so be patient while this task completes. Subsequent deployments to the emulator will go much more quickly if the emulator is already running.

Once this is all complete, your program will launch. Clicking the button will display the MessageBox, as you would expect (see Figure 1-7).

The test application in action

Figure 1.7. The test application in action

To stop the program, click the Stop Debugging button in Visual Studio. The IDE will return to edit mode, and your program will close on the emulator. The emulator will keep running, ready for any additional programs that you start.

Another way to stop the program is to click the Back button on the emulator. The default behavior when this button is clicked is to close the application and return to the phone's main page (although this behavior can be overridden, as we will see later on). This process will also return the IDE to edit mode. The fact that the Back button actually closes the application instead of simply putting it into the background is important, as we will need to hook into this if we want to allow the application to retain its state when it restarts.

Running on a Real Device

You will no doubt be pleased to hear that running your application on a real device is no more difficult than running it within an emulator, and it provides an extremely similar experience. There are a few steps that you will need to go through before you can begin working with the device, however. Let's take a look at the details now.

Registering the Device

Before you can deploy applications to a device, you must first have a Windows Phone developer account. These accounts are not free, though they are relatively inexpensive (currently priced at $99 per year, though this might change in the future). You will need this account before you can publish any of your finished games into the Windows Phone Marketplace, anyway, so there is not really any way to avoid this charge, even if you develop entirely on the emulator.

You can sign up for an account at the http://create.msdn.com web site. You will be required to prove your identity to Microsoft as part of this process and will receive e-mail notification telling you how to do this. The process might take a couple of days from start to finish.

Besides providing your personal details, you will also be able to provide banking details so that you can be paid for applications that you create and sell in the Marketplace.

Once your account is registered and active, the next step is to set the device up to connect to your PC. First, plug the device in and allow Windows to set up its drivers. This should be a completely automatic process.

Next you will need to install the latest Zune client software. An up-to-date version of this software is essential, so if you have an older version already installed, you will need to upgrade. This application is used for all data transfer and synchronization between the phone and your PC, and will need to be running all the time that you are working with the device. Without this, you will receive an error from Visual Studio when you attempt to deploy.

Once the Zune software has launched, you have to sign in to your Marketplace account, which allows the software to identify that you have registered for development and will unlock the deployment facility that Visual Studio needs to use to transfer your games and applications to the device. The device confirmation screens then appear, as shown in Figure 1-8, allowing you to set up the device for use with your PC.

Configuring the device inside the Zune software for use with the PC

Figure 1.8. Configuring the device inside the Zune software for use with the PC

The final step in setting up the device is to run the Windows Phone Developer Registration application on the PC. This is part of the Windows Phone Software Development Kit, and can be found in the Start menu inside All Programs/Windows Phone Developer Tools. When launched, the application displays a screen like the one shown in Figure 1-9.

The Windows Phone Developer Registration application

Figure 1.9. The Windows Phone Developer Registration application

You need to enter the username and password of your developer account and then click the Register button. After a few seconds, you should be notified that the phone was successfully registered. At this point you are finally ready to begin working with your phone in Visual Studio.

These steps only need to be performed once for each device that you use.

Deploying to the Device from Visual Studio

Now we are ready to deploy our project to the device from inside Visual Studio.

First, with the Zune software running in the background on your PC, connect your device to the PC and ensure that it is recognized by Windows. Once everything is ready, choose to deploy your application to the device rather than the emulator. This is done by dropping down the Device combo box in the toolbar and selecting Windows Phone 7 Device, as shown in Figure 1-10. When you next start your program, Visual Studio will connect to the device and then install and launch the application executable.

Choosing to launch the application on a physical device

Figure 1.10. Choosing to launch the application on a physical device

Note

For deployment to succeed, the phone must be switched on, and the lock screen must not be displayed. If these conditions are not met, a deployment error will occur, although Visual Studio usually provides good feedback about what the problem is to help you figure out how to proceed.

Unsurprisingly, the project running on the phone looks and behaves just as it did in the emulator. Congratulations, you have written and deployed your first Windows Phone application!

Debugging

Now that you have a simple application written and working, let's take a closer look at some of the debugging features that are available.

The powerful debugging tools that can be used within the Visual Studio IDE make development systems from the past look extremely primitive in comparison. We can use all these tools for Windows Phone development, making tracking down problems simple.

Breakpoints

First, try setting a breakpoint on the line of code containing the MessageBox function call. Launch the program (on a real device or the emulator), and click the button within the page. As you would expect, the breakpoint triggers just as it would on a desktop application.

From here, you can explore all the usual attributes of your application: the call stack, object property windows, visualizers, and immediate window commands. Everything is present and working.

The one useful feature that is not available, however, is "edit and continue." Unfortunately, because the application is actually running outside of Visual Studio's controlled environment, such changes cannot be applied at runtime and will need to be held back until the IDE returns to edit mode.

Debug Output

At any stage within your application you can display text in Visual Studio's Output window. This is done in just the same way as for a desktop application—by using the System.Diagnostics.Debug object. To test this, modify the button click handler as shown in Listing 1-2.

Example 1.2. Writing text to the Debug Output window

private void button1_Click(object sender, RoutedEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("Debug text");
    MessageBox.Show("Hello Windows Phone!", "Testing", MessageBoxButton.OK);
}

Each time you click the button, you will now see your debug text appear within the IDE, as shown in Figure 1-11.

Debug text appearing in the Debug Output window

Figure 1.11. Debug text appearing in the Debug Output window

Tip

If the Output window is not displayed, it can be opened by selecting View/Output from Visual Studio's menu. If the Output window is open but no text is appearing, ensure that the "Show output from" combo box in the window toolbar is set to Debug, as shown in Figure 1-11.

Getting Help

Sooner or later you will run into a development problem that you cannot solve on your own. A number of great resources at your disposal can provide insight and inspiration to keep you moving. Here are some of them.

MSDN

As you would expect from one of Microsoft's products, comprehensive and detailed documentation is available for all aspects of Windows Phone development and the .NET CF. Provided you have it installed, MSDN is an excellent source of help and is never farther away than a quick press of the F1 key.

Search Engines

The Web is, as ever, an indispensible fountain of information. When searching, try to accompany your search phrase with "windows phone" or "windows phone 7" (including the quotation marks).

Microsoft's Windows Phone Developer Center

The Developer Center can be found at the following URL:

http://create.msdn.com/

The site hosts a large variety of articles, development tips, frequently asked questions, and code samples. Also of particular interest is the Forums link, which leads to a number of very active message forums. There's a good chance that someone will be able to offer you some assistance.

Community Sites

Some excellent community sites have built up around the XNA and Silverlight technologies used on Windows Phone 7, and they are a good place to read and ask questions if you need assistance.

For XNA, you can visit http://creators.xna.com for one such community. For Silverlight, http://www.silverlight.net provides similar resources. Besides their forums, both sites are packed with information and downloads, and are well worth visiting.

Windows Phone Game Development

We've spent a lot of time discussing development in general, but we have not yet looked at game development. We will start preparing to actually write a game in the next chapter, but let's conclude this overview of Windows Phone software development by thinking about what types of games we can create and the technologies available to create them.

Suitable Games

Although the power of the Windows Phone graphics hardware might not be approaching that of dedicated PC graphics cards, it is nonetheless very capable for a mobile device. Coupled with the lower screen resolution of the phone compared to that of a typical PC monitor, very impressive 3D graphical displays should be well within your reach.

Not everything has to reach into the third dimension, however. Two-dimensional games can be extremely enjoyable and rewarding to play, too. We can do great things with the more laid-back game genres such as strategy, role playing, and puzzle games. Well-crafted games such as these can become extremely popular because the immediate "switch on and play" nature of the device is ideal for people who have only a few spare minutes to dedicate to gaming before real life gets in the way. This type of game is well suited to the phone and has a potentially large audience.

Board and card games are examples of other styles that are easily accessible to a wide audience, and they convert well to handheld devices. In particular, the ability to physically drag cards around the game with a finger leads to a satisfying feeling of involvement.

Novelty games have recently become popular on other platforms such as the iPhone, allowing users to create and distort photographs of their friends, to create sound effects in response to interactions with the device, and a variety of other unusual things. If you have creative flair and imagination to spare, this could be an interesting area to explore!

Selecting an Application Framework

One of the first decisions that you need to make when you begin programming a game is which application framework to use: XNA or Silverlight.

XNA

XNA is the framework of choice for anything involving 3D graphics, full-screen graphical effects, or large numbers of moving objects. The graphical approach of XNA relies on completely redrawing the whole screen every frame (30 times per second or more), and it's just as easy to redraw things in different positions as it is to redraw them unmoved.

The whole architecture of an XNA game application is based around rapid and continuous updates of the graphics onscreen. We have full access to all the device features, including the use of the multitouch screen, accelerometer, and sound and music output.

Silverlight

For games that require a little less graphical grunt, Silverlight is a very capable environment for game development. Ideal for puzzle games and other games that don't require dozens of constantly moving objects, Silverlight's graphical capabilities still provide features such as transparency, scaling, and rotation of graphics—all of which are very useful for games.

Games that require a rich graphical user interface (GUI) are likely to be obvious candidates for Silverlight. Its page design capabilities are highly flexible, offering everything from labels to fully working web browser controls—unlike XNA, which has no built-in user interface features at all and requires everything to be manually programmed.

As with XNA, the device features are all available in Silverlight, including the multitouch display and accelerometer. Unlike XNA, Silverlight is event-driven, so your coding model will generally be responding to event calls rather than polling the device state.

Silverlight is also much better at displaying text than XNA. Whereas XNA relies on bitmap representations of fonts (which become blocky and are distorted if they are drawn too large), Silverlight uses vector-based fonts, allowing them to be zoomed without any such distortion.

A nice side effect of developing for Silverlight is that games can, with some work, be converted to run on a PC within a web browser. This can be very useful for helping to promote your game—instead of just telling your audience about it, you can actually let them play it immediately at the click of a button.

Welcome to the World of Windows Phone Development

This concludes our overview of the .NET CF development process. I hope you are enthusiastic and excited about the opportunities of developing for the Windows Phone platform.

Please spend a little time experimenting with the capabilities of the environment and the .NET CF libraries. We will look at exactly what we can do with .NET CF in much more detail in the following chapters, but for now, do get comfortable with building and launching applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.222.89