Windows Phone: From Idea to Published Game in 75 minutes

78
Windows Phone and XNA Creating and publishing a game in 75 minutes Rob Miles Microsoft MVP University of Hull, UK

description

More info on http://www.techdays.be

Transcript of Windows Phone: From Idea to Published Game in 75 minutes

Page 1: Windows Phone: From Idea to Published Game in 75 minutes

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

Rob MilesMicrosoft MVPUniversity of Hull, UK

Page 2: Windows Phone: From Idea to Published Game in 75 minutes

Agenda

• Windows Phone XNA overview• Getting an idea• Building a game• Getting market ready• Publishing the game• Useful resources

Page 3: Windows Phone: From Idea to Published Game in 75 minutes

Windows Phone XNA overview

Page 4: Windows Phone: From Idea to Published Game in 75 minutes

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 5: Windows Phone: From Idea to Published Game in 75 minutes

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 6: Windows Phone: From Idea to Published Game in 75 minutes

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 7: Windows Phone: From Idea to Published Game in 75 minutes

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 8: Windows Phone: From Idea to Published Game in 75 minutes

Making a game

Page 9: Windows Phone: From Idea to Published Game in 75 minutes

Getting started

• Make an empty project

• Add your resources• Graphics, sound, 3D

models, scripts

• Fill in the methods in the project

Page 10: Windows Phone: From Idea to Published Game in 75 minutes

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 11: Windows Phone: From Idea to Published Game in 75 minutes

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 12: Windows Phone: From Idea to Published Game in 75 minutes

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 13: Windows Phone: From Idea to Published Game in 75 minutes

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 14: Windows Phone: From Idea to Published Game in 75 minutes

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 15: Windows Phone: From Idea to Published Game in 75 minutes

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 16: Windows Phone: From Idea to Published Game in 75 minutes

Demo 1Drawing smudge

Page 17: Windows Phone: From Idea to Published Game in 75 minutes

Where to next?

• We have an incredibly simple sprite engine• And we have drawn one sprite

• Now we need to build on this• How about making a bunch of smudges

and drawing with them?

Page 18: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

Demo 2Smudge drawing

Page 24: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

Demo 3Smudge growing

Page 27: Windows Phone: From Idea to Published Game in 75 minutes

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 28: Windows Phone: From Idea to Published Game in 75 minutes

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 29: Windows Phone: From Idea to Published Game in 75 minutes

Demo 4Coloured smudges

Page 30: Windows Phone: From Idea to Published Game in 75 minutes

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 31: Windows Phone: From Idea to Published Game in 75 minutes

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 32: Windows Phone: From Idea to Published Game in 75 minutes

Demo 5Shorter smudges

Page 33: Windows Phone: From Idea to Published Game in 75 minutes

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 34: Windows Phone: From Idea to Published Game in 75 minutes

Demo 6Finished program

Page 35: Windows Phone: From Idea to Published Game in 75 minutes

Where to next?

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

type game• The sprite framework makes this

possible…

Page 36: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

Getting Market Ready

Page 38: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

Performance Analysis Settings

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

Page 40: Windows Phone: From Idea to Published Game in 75 minutes

Analysis Data

• The analysis provides plenty of good data

Page 41: Windows Phone: From Idea to Published Game in 75 minutes

Demo 7Performance testing

Page 42: Windows Phone: From Idea to Published Game in 75 minutes

Creating an Application

Page 43: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

XAP File Anatomy

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

contents and the application

Page 45: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

Editing the manifest

• You can edit this file from Visual Studio

• It is in the Properties entry of the solution

Page 50: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

The Windows Phone Marketplace

57

Page 58: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

Marketplace Submission

Page 65: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

The Marketplace Test Kit

• The Marketplace Test Kit lets you perform the same tests on your application before you submit it

67

Page 68: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

Advertising SDK

Page 71: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

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: Windows Phone: From Idea to Published Game in 75 minutes

© 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.