Students to Business Day 2012: Rob Miles

78

Transcript of Students to Business Day 2012: Rob Miles

Page 1: Students to Business Day 2012: Rob Miles
Page 2: Students to Business Day 2012: Rob Miles

Windows Phone and XNA Creating and publishing a game in 50 minutes

Rob MilesMicrosoft MVPUniversity of Hull, UK

Page 3: Students to Business Day 2012: Rob Miles

Agenda• Windows Phone XNA overview

• Getting an idea• Building a game

• Getting market ready• Publishing the game

• Useful resources

Page 4: Students to Business Day 2012: Rob Miles

Windows Phone XNA overview

Page 5: Students to Business Day 2012: Rob Miles

Windows Phone as an XNA platform

• Windows Phone is a great platform for games• Performance is impressive, especially in 3D• You can use all the hardware and sensors in your

Windows Phone games• Potential for Xbox Live integration• Support for in-game advertising

Page 6: Students to Business Day 2012: Rob Miles

Quick overview of XNA• XNA provides everything you need to get started • Full Content Management (integrated into Visual Studio)• Support for 2D Sprite-based gameplay • Support for 3D games

• Common behaviours across the Windows PC, Xbox 360 and Windows Phone• One game engine can run on all platforms

Page 7: Students to Business Day 2012: Rob Miles

How XNA (and all) games work• Initialise all the resources at the start• fetch all textures, models, scripts etc

• Repeatedly run the game loop:• Update the game world• read the controllers, update the state and position of game

elements• Draw the game world• render the game elements on the viewing device

Page 8: Students to Business Day 2012: Rob Miles

METHODS IN AN XNA GAME• XNA Game class contains game methods• Initialise all the resources at the start• The Initialize and LoadContent methods

• Repeatedly run the game loop:• Update the game world – Update• Draw the game world - Draw

Page 9: Students to Business Day 2012: Rob Miles

Making a game

Page 10: Students to Business Day 2012: Rob Miles

Getting started• Make an empty project• Add your resources• Graphics, sound, 3D

models, scripts• Fill in the methods in

the project

Page 11: Students to Business Day 2012: Rob Miles

Our single game asset - Smudge• We are going to write a

smudge based game• This is our starting smudge• It is really a sprite in our game

• You can use any texture that you like

Page 12: Students to Business Day 2012: Rob Miles

Sprite behaviours

• These are the things that our sprite can do• Note that each method is given a reference to the

parent game

interface ISprite{ void Reset(SamplerState game); void Draw(SmudgeGame game); void Update(SmudgeGame game);}

Page 13: Students to Business Day 2012: Rob Miles

Creating a sprite

• This code runs in the LoadContent method• It creates a new sprite called smudge• smudge is red, at (0,0), a 20th the width of the screen and

not rotated

Texture2D smudgeTexture = Content.Load<Texture2D>("Smudge");

smudge = new Sprite(this, smudgeTexture, Vector2.Zero, Color.Red, 20, 0);

Page 14: Students to Business Day 2012: Rob Miles

Toughest slide in the presentation!public virtual void Draw(SmudgeGame game){ game.spriteBatch.Draw( spriteTexture, // texture of sprite spritePosition, // vector position on screen null, // source rectangle in texture (all of it) spriteColor, // colour of the light spriteRotation, // rotation – in radians spriteOrigin, // centre of sprite – position and rotation spriteScale, // scale – scaled to fit SpriteEffects.None, 1); // draw everything at the same depth}

Page 15: Students to Business Day 2012: Rob Miles

This is the draw behaviour for the spritepublic virtual void Draw(SmudgeGame game){ game.spriteBatch.Draw( spriteTexture, // texture of sprite spritePosition, // vector position on screen null, // source rectangle in texture (all of it) spriteColor, // colour of the light spriteRotation, // rotation – in radians spriteOrigin, // centre of sprite – position and rotation spriteScale, // scale – scaled to fit SpriteEffects.None, 1); // draw everything at the same depth}

Page 16: Students to Business Day 2012: Rob Miles

Easiest slide in the presentation

• This the update method for the sprite• At the moment it does nothing• We can extend the Sprite class to add new types of

behaviours

public virtual void Update(SmudgeGame game){}

Page 17: Students to Business Day 2012: Rob Miles

Where to next?• We have an incredibly simple sprite engine• Now we need to build on this• How about making a bunch of smudges and drawing

with them?

Page 18: Students to Business Day 2012: Rob Miles

Making a playfield

• This is my game playfield• It contains all the sprites on the screen• The game will work through the list and draw all the

sprites on each draw cycle

List<ISprite> gameSprites = new List<ISprite>();

Page 19: Students to Business Day 2012: Rob Miles

Drawing the sprites

• This is how the game draws all the sprites on the screen

• We can add sprites to the collection and they will be drawn for us

foreach (ISprite sprite in gameSprites) sprite.Draw(this);

Page 20: Students to Business Day 2012: Rob Miles

Where to next?• We could make sprites that bounce around the

screen or fly off the sides• I thought it might be nice to get the user drawing

with the sprites• This is really easy to do with the touchpad

Page 21: Students to Business Day 2012: Rob Miles

Using the touchpad

• This turns on the touchpad and enables tap and drag events

protected override void Initialize(){ TouchPanel.EnabledGestures = GestureType.Tap | GestureType.FreeDrag; base.Initialize();}

Page 22: Students to Business Day 2012: Rob Miles

Adding smudges

• This code runs in the Draw method• Each time we get a touch gesture we add a new

smudge where the gesture is

while (TouchPanel.IsGestureAvailable){ GestureSample gesture = TouchPanel.ReadGesture();

gameSprites.Add( new Sprite(this, smudgeTexture, gesture.Position, Color.Red, 20,0));}

Page 23: Students to Business Day 2012: Rob Miles

Demo 1Drawing with smudges

Page 24: Students to Business Day 2012: Rob Miles

Where to next?• We can now draw with smudges, which is kind of fun• Now we need to build on this• First thing we need to do is animate the sprite• Make it grow over time?

• We can do this by making a child class with a new Update behaviour

Page 25: Students to Business Day 2012: Rob Miles

Make a sprite that grows…

• This override of the Update method grows the sprite

class GrowingSprite : Sprite, Isprite{ float spriteGrowSpeed = 0.05f; public override void Update(SmudgeGame game) { spriteScale += spriteGrowSpeed; base.Update(game); }}

Page 26: Students to Business Day 2012: Rob Miles

Where to next?• The game (if that’s what it is) is still boring• We need to make it more interesting• Perhaps a few different colours would help• Setting the draw colour of a white texture causes

the texture to appear to be that colour

Page 27: Students to Business Day 2012: Rob Miles

Creating random colours

• This returns a random colour value that can be used to draw each smudge

System.Random colorRand = new Random();

Color randomColor(){ int r = colorRand.Next(256); int g = colorRand.Next(256); int b = colorRand.Next(256); return Color.FromNonPremultiplied(r, g, b, 255);}

Page 28: Students to Business Day 2012: Rob Miles

Demo 2Coloured growing smudges

Page 29: Students to Business Day 2012: Rob Miles

Where to next?• This is looking prettier, but we still haven’t got a

game• Also if we add a very large number of smudges the

program slows right down• But it is quite fun to steer the line around the screen

Page 30: Students to Business Day 2012: Rob Miles

Clearing away smudges

• This code removes old smudges from the list

while (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture();

if (gameSprites.Count > smudgesLength) gameSprites.RemoveAt(0);

gameSprites.Add(new GrowingSprite(this, smudgeTexture, gesture.Position, randomColor(), 20, 0));}

Page 31: Students to Business Day 2012: Rob Miles

Demo 3Shorter smudges

Page 32: Students to Business Day 2012: Rob Miles

Efficiency and performance• This is not very efficient code• Although it is quick to write it results in objects

being created and destroyed as it runs• However, the objects are very small, and

performance seems to be fine• We can use the performance analysis tools to find

out what is going on if we hit problems

Page 33: Students to Business Day 2012: Rob Miles

Where to next?• We can add new sprite types• Sprite that drifts across the screen• Sprite that bounces off the edges• The game could produce these as well as drawing

Page 34: Students to Business Day 2012: Rob Miles

Demo 4Work in progress…

Page 35: Students to Business Day 2012: Rob Miles

Where to next?• We could use the accelerometer to control the

sprites• We could add images from the camera• We could animate the sprites• We could make the elements rotate• We could make a “Snake” type game• We could make a “Missile Command” type game• We could animate the sprites using sound imput

Page 36: Students to Business Day 2012: Rob Miles

Selling something• Don’t be afraid to send stuff out there to see if

anyone likes it• If you get good feedback, develop the idea• If you get nothing, move on to the next idea….

Page 37: Students to Business Day 2012: Rob Miles

Getting Market Ready

Page 38: Students to Business Day 2012: Rob Miles

Starting Performance Analysis• The performance analysis tool

will tell you where a program is spending most of its time

• Then you can consider optimising those parts

• It is activated from the Debug menu

Page 39: Students to Business Day 2012: Rob Miles

Performance Analysis Settings

• You can create and activate diagnostic settings that you can use and reuse as you develop the application

Page 40: Students to Business Day 2012: Rob Miles

Analysis Data

• The analysis provides plenty of good data

Page 41: Students to Business Day 2012: Rob Miles

Demo 7Performance testing

Page 42: Students to Business Day 2012: Rob Miles

Creating an Application

Page 43: Students to Business Day 2012: Rob Miles

The Windows Phone XAP file• The XAP file brings together all the elements

of your program application• It is the item that is actually pushed onto the

device when it is deployed• The XAP file provides a common format for all

Windows Phone apps & games• Declarative, manifest-based installation• Integrated into security model of phone• Tied to your developer identity

Page 44: Students to Business Day 2012: Rob Miles

XAP File Anatomy

• The XAP file is actually a zip file• It contains manifest files that describe the contents

and the application

Page 45: Students to Business Day 2012: Rob Miles

AppManifest File

• This file is built for you and identifies the components in the XAP file

<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="WindowsPhonePuzzle" EntryPointType="WindowsPhonePuzzle.App" RuntimeVersion="3.0.40624.0"> <Deployment.Parts> <AssemblyPart x:Name="WindowsPhonePuzzle" Source="WindowsPhonePuzzle.dll" /> </Deployment.Parts></Deployment>

Page 46: Students to Business Day 2012: Rob Miles

WMAppManifest.xml• The other manifest file is very important• It identifies the services that your application wishes to make

use of• It also configures the application itself

• The Marketplace deployment mechanisms can use this to ensure that users know what an application is going to do

• An application that attempts to use a service which is not requested in the WMAppManifest will be rejected by the Marketplace validation process

Page 47: Students to Business Day 2012: Rob Miles

WMAppManifest.xml Capabilities

• The default file requests all capabilities• However, an application should only ask for the ones it needs

<Capabilities><Capability Name="ID_CAP_LOCATION"/> <Capability Name="ID_CAP_MEDIALIB"/> <Capability Name="ID_CAP_PHONEDIALER"/> <Capability Name="ID_CAP_PUSH_NOTIFICATION"/> <Capability Name="ID_CAP_SENSORS"/> <Capability Name="ID_CAP_WEBBROWSERCOMPONENT"/> <Capability Name="ID_CAP_ISV_CAMERA"/> <Capability Name="ID_CAP_CONTACTS"/> <Capability Name="ID_CAP_APPOINTMENTS"/></Capabilities>

Page 48: Students to Business Day 2012: Rob Miles

WMAppManifest.xml Details

• The file also tells the Marketplace about your program, name, type, genre

• You need to edit this file so that it holds valid information about your program

<App xmlns="" ProductID="{eb43b2c2-b7e9-4e5c-8aea-8047eb5e335f}" Title="FunkyCamera" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal" Author="FunkyCamera author" Description="Sample description" Publisher="FunkyCamera">

Page 49: Students to Business Day 2012: Rob Miles

Editing the manifest

• You can edit this file from Visual Studio

• It is in the Properties entry of the solution

Page 50: Students to Business Day 2012: Rob Miles

Making Icons

• You will need to prepare icons of a selection of sizes• Then you need to edit your project files to refer to

these

Page 51: Students to Business Day 2012: Rob Miles

Finding your XAP

• If you want to find your XAP file it is held alongside your binaries • Remember to make a release build

• Rename it to ZIP if you want to look inside

Page 52: Students to Business Day 2012: Rob Miles

XAP Rules• A XAP file should not be more than 20Mb in size for

Over the Air (OTA) distribution • The limit for all files is 400Mb• For full details of submission requirements and

process description go here:http://go.microsoft.com/?linkid=9730558

Page 53: Students to Business Day 2012: Rob Miles

Sharing your XAP files• If you want people to run try your app but you don’t

want to give them the source you can distribute the XAP file instead

• They can then load it onto a developer device or the emulator

• They would use the XAP Deployment tool to do this

Page 54: Students to Business Day 2012: Rob Miles

Local Application Deployment• You can deploy a XAP file onto

an unlocked device, or the emulator by using the Application Deployment tool• Can deploy to the emulator or a

device• You can distribute finished

applications for test

Page 55: Students to Business Day 2012: Rob Miles

Obfuscation• If you send someone your XAP file they can use

disassemblers and other programs to unpick your assemblies and find out how they work• They can also obtain all your assets (images and sounds)

• An obfuscator tool will change the layout and variable names in your code to make it harder to decode the way a program works

Page 56: Students to Business Day 2012: Rob Miles

Adding Obfuscation• There are a number of tools that will perform this

obfuscation for you• The Windows Phone Marketplace provides access to

one from PreEmptive solutions that is worth a lookhttp://www.preemptive.com/windowsphone7.html

Page 57: Students to Business Day 2012: Rob Miles

The Windows Phone Marketplace

57

Page 58: Students to Business Day 2012: Rob Miles

Marketplace Rules• The Marketplace is the only way you can get

executable content onto a phone• Users can buy applications and deploy them onto

their devices• Developers can write applications and deploy them

to their own devices for testing• Registered developers can use up to 3 devices• Student developers can use one device

Page 59: Students to Business Day 2012: Rob Miles

Joining the Marketplace• Register to be a member of the marketplace for $99

per year• Students can register for free via Dreamspark• Join at: http://create.msdn.com

Page 60: Students to Business Day 2012: Rob Miles

Payment• Developers can set a price for an application or give it

away free• Developers receive 70% of the price paid for the

application• Payment starts once the developer has earned up to $200• The payment is made by bank transfer• All payments are from the USA, which can cause some

issues• Very good support on the developers site and the Windows Phone

Forums for this

Page 61: Students to Business Day 2012: Rob Miles

Free and Paid Applications• Developers are limited in the number of free

applications they can make available• Only 100 (!) free apps per developer per year• Can publish further free applications at a extra cost of $20

per application• Developers can publish as many paid applications

as they like

Page 62: Students to Business Day 2012: Rob Miles

Applications for sale• Applications can be free or paid• Developers can also allow customers to use an

application in “try before buy” mode• Your application can determine which mode it is

running in by calling a status API

Page 63: Students to Business Day 2012: Rob Miles

Using Trial Mode

• It is easy for an application to determine whether it is running in Trial mode • But remember that a paid application with Trial Mode will not

show up as free in the Marketplace• It might be more effective to also distribute a free “lite”

version of your application

using Microsoft.Phone.Marketplace;

LicenseInformation info = new LicenseInformation();if ( info.IsTrial() ) { // running in trial mode}

Page 64: Students to Business Day 2012: Rob Miles

Marketplace Submission

Page 65: Students to Business Day 2012: Rob Miles

Application Validation• When you submit your application for validation the

system performs a number of automated tests• Checks if the application makes use of any capabilities

that were not specified• Checks for any unmanaged or disallowed libraries• Ensures that all the required assets are provided

• Then the application is manually tested to ensure proper behaviour in a number of scenarios

Page 66: Students to Business Day 2012: Rob Miles

Validation Results• The testing process takes a few days and generates

a testing report that you can use to fix the problems• This will include specific feedback on the issues that

were identified

Page 67: Students to Business Day 2012: Rob Miles

The Marketplace Test Kit• The Marketplace Test

Kit lets you perform the same tests on your application before you submit it

67

Page 68: Students to Business Day 2012: Rob Miles

Testing Kit User Interface• The test kit checks all

aspects of the submission, including the required assets

• It also itemises the manual tests

Page 69: Students to Business Day 2012: Rob Miles

Private Beta Testing• Apps can now be

submitted for Private Beta testing

• You can send invitation emails to up to 100

• They have 90 days to test your application

Page 70: Students to Business Day 2012: Rob Miles

Advertising SDK

Page 71: Students to Business Day 2012: Rob Miles

Adding Advertisements to Games • Very easy to incorporate ads

into XNA games• Players can click through an

advertisement to a web site or call the advertiser from within your game

• You get 70% of the revenue

Page 72: Students to Business Day 2012: Rob Miles

Microsoft pubCenter

• Sign up here so that you can incorporate ads in your games• http://pubcenter.microsoft.com

• Find out more about Windows Phone Advertising• http://advertising.microsoft.com/mobile-apps

Page 73: Students to Business Day 2012: Rob Miles

XNA Resources• XNA Game Studio 4.0 on MSDN http://msdn.microsoft.com/en-us/library/bb200104.aspx

• XNA Game Development Resource Page http://create.msdn.com/en-us/education/gamedevelopment

• Sean Hargreaves Blog http://blogs.msdn.com/b/shawnhar/

• Farseer Physics Engine http://farseerphysics.codeplex.com

Page 74: Students to Business Day 2012: Rob Miles

Windows Phone resources• Emulator skin switcher

http://wp7emuskinswitcher.codeplex.com/

• “Little Watson” for XNAhttp://www.limguohong.com/2011/05/error-reporting-for-windows-phone-7-little-watson-xna-version/

• Lots of resources:http://weblogs.asp.net/bsimser/archive/2012/01/29/the-big-dummies-guide-for-windows-phone-developer-resources.aspx

• Mehttp://www.robmiles.comTwitter @RobMiles

Page 75: Students to Business Day 2012: Rob Miles

Subtle Plug • If you are new to C#

programming and XNA game development you could do a lot worse than buy my book

Page 76: Students to Business Day 2012: Rob Miles

Make Stuff and Have Fun• The Windows Phone platform is very powerful and

very easy to develop for• If you already have C# and Visual Studio skills this is

a great place to take them further• If you are learning how to write .NET applications

and games the Windows Phone is a great place to hone your skills and show off in the Marketplace

Page 77: Students to Business Day 2012: Rob Miles

Be what’s next: Windows Phone• Find everything here

http://aka.ms/mbl-phone/start • Download your free Windows Phone Dev Tools

http://aka.ms/mbl-phone/tools• Channel9 ‘Get to Mango’ series

http://aka.ms/mbl-phone/mango• Register as a developer

http://aka.ms/mbl-phone/register

Page 78: Students to Business Day 2012: Rob Miles

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.