Students to Business Day 2012: Rob Miles
-
Upload
frederik-bruyne -
Category
Technology
-
view
501 -
download
0
Transcript of 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
Agenda• Windows Phone XNA overview
• Getting an idea• Building a game
• Getting market ready• Publishing the game
• Useful resources
Windows Phone XNA overview
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
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
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
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
Making a game
Getting started• Make an empty project• Add your resources• Graphics, sound, 3D
models, scripts• Fill in the methods in
the project
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
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);}
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);
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}
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}
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){}
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?
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>();
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);
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
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();}
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));}
Demo 1Drawing with smudges
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
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); }}
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
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);}
Demo 2Coloured growing smudges
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
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));}
Demo 3Shorter smudges
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
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
Demo 4Work in progress…
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
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….
Getting Market Ready
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
Performance Analysis Settings
• You can create and activate diagnostic settings that you can use and reuse as you develop the application
Analysis Data
• The analysis provides plenty of good data
Demo 7Performance testing
Creating an Application
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
XAP File Anatomy
• The XAP file is actually a zip file• It contains manifest files that describe the contents
and the application
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>
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
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>
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">
Editing the manifest
• You can edit this file from Visual Studio
• It is in the Properties entry of the solution
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
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
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
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
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
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
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
The Windows Phone Marketplace
57
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
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
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
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
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
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}
Marketplace Submission
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
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
The Marketplace Test Kit• The Marketplace Test
Kit lets you perform the same tests on your application before you submit it
67
Testing Kit User Interface• The test kit checks all
aspects of the submission, including the required assets
• It also itemises the manual tests
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
Advertising SDK
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
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
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
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
Subtle Plug • If you are new to C#
programming and XNA game development you could do a lot worse than buy my book
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
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
© 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.