Design Considerations for Building 2D, 3D Games for Windows Phone 7

Introduction

By dictating the hardware specifications for phones designed to run the Windows Phone 7 operating system, Microsoft has ensured that, irrespective of the manufacturer, the device will conform to specified standards. Microsoft has achieved this by specifying the minimum hardware specification robust enough to run immersive 2D and 3D experiences and having the same touch input.

Shader Effects Available on the Windows Phone 7 (WP7) Platform

The GPU on the phone allows for having 5 configurable shader effects:

  • BasicEffect
  • DualTextureEffect
  • AlphaTestEffect
  • SkinnedEfect
  • EnvironmentMapEffect

The limitation is that you cannot author your own “shader effects”. This is partly a design choice taken by Microsoft to balance performance and battery life.

The CPU also supports hardware accelerated 2D sprite drawing.

Here is a tabular report on which effect is suitable for which scenarios.

Effect Designed usage Cost
BasicEffect Blinn-Phong shading
Texture is optional
Fog is optional
Targeted for simple visuals
Cheaper than other effects
DualTextureEffect Blends two textures
Good visuals at low pixel cost
Primarily targeted for lightmaps, detail textures and decals
Intermediate
AlphaTestEffect Targeted for billboards and imposters
Adds pixel kill effect
Standard blending comes free with its associated effects
Intermediate
SkinnedEfect Targeted for animated models and instancing (think XBOX 360’s Call of Duty Modern Warfare like game effects)
It can animate bones on CPU and vertex skilling done by GPU
Allows up to 4 weights per vertex
Very High
EnvironmentMapEffect This is for the shiniest application
Cheap way to fake complex lights
High

Considerations to Make When Developing 2D and 3D Gaming Apps for WP7

When designing applications, it is often a balancing act between pixel cost, framerate and the number of pixels rendered.

Framerate – Since the refresh rate of the phone is 30 Hz, it does not merit updating the display faster than that. IF you render faster than that, it is a waste of CPU/GPU and battery life.

You can set the refresh rate by setting the Game.TargetElapsedTime property.

  Game.TargetElapsedTime = TimeSpan.FromSeconds(1f/30);

Pixel – When processing power or battery life is premium, opt for cheaper effects. Minimize on overdrawing.

If you see brighter areas, it might indicate that you are overdrawing. Choose to draw untextured and blending in a desired texture where required. This saves CPU instructions by avoiding texture calculations where not needed.

Since the phone cannot render more than 800 x 480 at the best (in its current iteration), make sure your frames do not have more than the required pixels.

Use dedicated hardware scaler if your calculated frames are smaller than the screen size. Reverse operation is a waste of CPU power. The hardware scaler does not consume any GPU and is of higher quality than bilinear upsampling.

  • RenderTargetUsage – When possible, avoid preserving the contents of RenderTargetUsage by calling the RenderTargetUsage.PreserveUsage.
  • BlendState – Move the initialization of the BlendState to startup. And don’t create a new BlendState object to assign to the Device’s BlendState property. Rather, have s static BlendState object which you initialize at Startup and keep re-using this static copy to assign to the device’s BlendState property per frame
  • VertexBuffer – In cases where your code frequently works with a vertex buffer, it is recommended that the buffer be instantiated or derived from DynamicVertexBuffer instead of VertexBuffer. Avoid use of the VertexBuffer.SetData API. Rather use device.DrawUserPrimitives or DynamicVertexBuffer.SetData.

3D Models

All usual 3D models are available for the phone platform.These models get imported by the content manager simplifying the port of existing Xbox games to the Windows Phone platform.

Summary

In this article, we saw a variety of design considerations to be made when building 2D and 3D games for the Windows Phone 7 platform. I hope you found this information useful and will be able to author better games for the WP7 platform.

Related Articles

More by Author

Must Read