Udostępnij za pośrednictwem


Choosing the right project template for your game for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Windows Phone 8 applications belong to one of two categories. Managed apps are based on managed code, but you can also invoke native code from this application type. The other application type is referred to as a “Direct3D app”. You cannot invoke managed code from within a Direct3D app. In Windows Phone 8, many of the phone features are exposed via Windows Phone Runtime APIs, which are accessible from both native and managed code. Many application scenarios can be achieved with either a managed app or a Direct3D app. But even though you can achieve similar results, there are some big differences in the structure, implementation, and available APIs for each application type. It’s important that you understand these differences and choose the right model for you app before you start coding.

This topic contains the following sections.

Managed applications

Windows Phone 8 provides several different project templates for managed apps all of which can be found in Visual Studio under Templates->Visual C#-> Windows Phone or Templates->Visual Basic-> Windows Phone in the New Project dialog. The following list describes some of the features of a managed app.

  • App Model – The app model for managed apps is almost identical to that of previous versions of Windows Phone. Your application will consist of a main Application object and one or more PhoneApplicationPage objects, all of which are implemented in XAML and C# or XAML and VB.NET. Each page implements a user interface and the user navigates between these pages to access different parts of your application.

  • UI – The user interface for managed apps is defined using XAML. There is a large library of controls available that support data binding and which you can layout easily in the designer built-in to Visual Studio and Blend for Visual Studio.

  • Exclusive Features – The following features are available only to managed apps and cannot be used by native-only applications.

    • Background Agents

    • Browser Control

    • Map Control

    • Background Transfer Service

    • Live Tiles

    • Push Notifications

    • The Windows Phone Ad Control

    • Localized resources

    • XAML controls

  • Because the managed runtime is invoked, startup time may be slightly slower and there is a small amount of additional memory used. Except when invalidating XAML controls, causing them to be redrawn, the performance degradation of a managed app app is negligible when compared to a pure native app.

It is possible to create a game using XAML to provide the entire UI. However, it is also possible to create a managed game that uses Direct3D to render 3D graphics to the screen. For this type of app there are two special project templates.

The XAML with Direct3D project template

This template is recommended if you want to render 3D graphics within a XAML UI. This template uses the DrawingSurface control to display Direct3D graphics on the screen. The DrawingSurface is like any other XAML control in that it can be placed anywhere on the screen, above or next to other XAML controls. The Direct3D code that actually renders the graphics is implemented in a separate Windows Phone Runtime component.

The Direct3D with XAML project template

This template is recommended if you want to create a game that only uses the managed app as a thin wrapper around an essentially native game in order to take advantage of some of the features that are only available to managed apps, such as live tiles. This template uses the DrawingSurfaceBackgroundGrid control to display Direct3D graphics on the screen. Unlike the DrawingSurface control, this control must be placed at the root of the XAML tree and always covers the entire screen. Like the other template, the Direct3D code for rendering graphics is implemented in a separate Windows Phone Runtime component. The frame rate of a Direct3D with XAML app is slightly better than a XAML with Direct3D app.

Direct3D apps

Direct3D apps are written entirely in native code. Casual developers may find developing a Direct3D app more challenging than developing a comparable managed app due to the fact that so many of the features available to managed apps in the form of robust, high-level managed APIs must be implemented from scratch using native code. This is especially true for UI components as there are no pre-made button, list, or text box controls available for pure native apps – although some of these may be provided by third party libraries. Advanced developers and those targeting multiple platforms, may find it easier and more flexible to use this project type. The following are some of the features of a Direct3D app.

  • Project Template – Direct3D apps can be created in Visual Studio by creating a new project and selecting the Direct3D Application project template under Templates->Visual C++ in the New Project dialog.

  • App Model - The Direct3D apps application model reflects the Windows 8 design principles. This model uses the CoreApplication object which manages application lifecycle events and then hands off to your implementation of the IFrameworkView interface. This interface exposes a Run method that hosts your game loop. In this model, there is no built-in concept of navigation. You simply draw to the screen according to the needs of your app.

  • UI - A Direct3D app does not support XAML or any of the built-in controls. If your app needs standard controls, like text boxes, buttons, or check boxes, you will need to write these from scratch or utilize third-party libraries.

Which application model is right for your app?

Managed – The UI framework for managed apps, including controls and page navigation, means application development is quicker and easier. Access to the Windows Phone Runtime library, the DrawingSurface control, which allows you to render graphics into a XAML page using Direct3D, and the ability to invoke native assemblies from managed code means that managed apps have comparable functionality and performance to native-only apps. There are several useful features, like Live Tiles, the Background Transfer Service, and several of the built-in Launchers and Choosers that can only be used in managed apps applications. managed apps apps will also allow you to reuse most code from Windows Phone OS 7.1 applications.

Direct3D - Direct3D apps are intended for apps for which the highest-possible performance is required, such as complex 3D games. There are no built-in controls or other user interface primitives. Pure native applications are easier to port to Windows 8 native applications as well as other platforms that support native code.

For more information on creating Direct3D apps, see Direct3D app development for Windows Phone 8.