WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop...

43
Building Your First Windows Phone Game with XNA Rob Cameron Architect Evangelist Microsoft WPH310

Transcript of WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop...

Page 1: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Building Your First Windows Phone Game with XNA

Rob CameronArchitect EvangelistMicrosoft

WPH310

Page 2: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Free Phone!

Stay to the End to Win!

Page 3: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Building your First Windows Phone Game with XNAAgenda

Windows Phone 7 as a Game Platform

Free Tools to Build Great Games

The Game LoopLoading ContentUpdate EventDraw Event

Input on Windows Phone 7

Building a Game with Your Friend AppHub

Page 4: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

The Windows Phone Hardware

Display

480x800 QVGA

Capacitive touch

4 or more contact points

Sensors

A-GPS, Accelerometer, Compass, Gyro

Camera

5 mega pixels or moreDedicated camera button

Hardware buttons

Start, Search, Back

CPU

ARMv7 Cortex/Scorpion 1G or higherQualcomm  MSM7x30, MSM8x55 800Mhz or higher

GPU

DirectX 9 acceleration

Multimedia

Common detailed specsCodec acceleration

Memory

256MB RAM or more8GB Flash or more

Page 5: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Windows Phone 7 as a Game Platform

5

Consistent hardware across OEMs

Performance is impressive, especially in 3D

Xbox Live is a key platform feature

Great tooling to facilitate game development

Page 6: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

XNA Game Studio 4.0

Develop games for

Windows PhoneSimplified graphics

API’s

Visual Studio 2010

integration

Enhanced audio

support

New configurable

effects

Page 7: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Game Loop Overview

7

Initialize Engine Load Resources

Free Resources

Get User Input

Calculate

Test Criteria

Give FeedBack

Typical Game LoopAll games do three thingsLoad content when they startUpdate the game world as quickly as possibleDraw the game world as quickly as possible

Each of these behaviors maps to a method in the game class created by Visual Studio at the time the XNA game project is created

Page 8: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

XNA Framework Game Loop Overview

8

Initialize() LoadContent()

UnLoadContent()

XNA Framework Game LoopAll games do three thingsLoad content when they startUpdate the game world as quickly as possibleDraw the game world as quickly as possible

XNA Framework provides the game loop framework on Windows Phone 7

Updatet()

Draw()

Page 9: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Loading Content

Manage assets in Visual Studio

Importers for common game data formats

Optimize data into binary format for efficient loading

Fully extensible

Compile time checking

Content projects external in XNA Game Studio 4.0

Page 10: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

LoadContent Method

protected override void LoadContent(){ // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here backgroundTexture = Content.Load<Texture2D>("Sprites\\background");}

Page 11: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Update and Draw Methods

Update() Method – Determines StateHandle inputCalculate movementDetermine collisionsUpdate animations and effects

Draw() Method – Renders SceneLoop through objects and draw

Page 12: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Update and Draw Methods

protected override void Update(GameTime gameTime){ // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here base.Update(gameTime);}

protected override void Draw(GameTime gameTime){ GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here base.Draw(gameTime);}

Page 13: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Game Development Process

Drawing Sprites

Moving Sprites

Create a Game Object

Handling Input

Page 14: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Drawing Sprites and Textures

Sprites – images you move around

Textures – background images, skin other objects

Texture2D represents an image

Instantiate Texture2D objects in LoadContent method

Page 15: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Drawing Sprites and Textures

protected override void Draw(GameTime gameTime){ GraphicsDevice.Clear(Color.CornflowerBlue);

spriteBatch.Begin(); spriteBatch.Draw(backgroundTexture, viewportRect, Color.White); foreach (GameObject enemy in enemies) { if (enemy.Alive) { spriteBatch.Draw(enemy.Sprite, enemy.Position, enemy.TintColor); } } spriteBatch.End(); base.Draw(gameTime);}

Page 16: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Moving Sprites

2D games are a great way to start game development

Cartesian coordinate system

Track position, direction, and speed for each object

Page 17: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Moving Objects

Vectors represent position and speed

Position Vector (10,10) – location on screen

Velocity Vector (0,10) – direction and speed

Page 18: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Moving Objects

Vectors represent position and speed

Changing length of velocity vector changes speed

positionVector += velocityVector

Page 19: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Demo

XNA Framework Basics

Page 20: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Game Object

Game objects make game development manageableEncapsulationInheritanceAll that good OO stuff

Implements mini game loopLoad contentUpdateDraw

Page 21: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Working with Game Objects

public override void Update(GameTime gameTime){ CheckForCollisions(); heroShip.Update(gameTime); statusBoard.Update(gameTime);

for (int i = 0; i < maxEnemies; i++) { enemies[i].Update(gameTime); } base.Update(gameTime);}

Page 22: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Working with Game Objects

Demo

Page 23: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Handling Input – Touch

Can capture up to four touch locationsDeclare a TouchCollectionTouchPanel.GetSate() to return a TouchCollection in Update()

Each TouchLocation has stateTouchLocationState.Invalid, Moved, Pressed, ReleasedA single user touch results in two TouchLocation items

One for Pressed, and one for Released

Page 24: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Handle Input – Accelerometer

Values for each axis are in the same range-1 to +1 in each axis

The Accelerometer can measure acceleration in X, Y, and Z

A value of 1 means 1G G is the acceleration due to gravity

Page 25: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Handling Input

Demo

Page 26: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

AppHub is Your Game Development Partner

Full game examples in 2D and 3D

Screen management sample

Sprite Sheet sample

Particle system sample

Many other samples for specific game dev tasks

http://create.msdn.com

Page 27: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Integrating App Hub Samples

Demo

Page 28: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Takeaways

Game Development is fun!

XNA Game Studio provides a powerful development tool

App Hub provides many great samples to get you started

Page 29: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Q&A

Questions?

And please fill out your evaluation form!

Page 30: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Related Content

WPH371-HOL | Game Development with Microsoft XNA Framework

WPH374-HOL | Tombstoning, Launcher and Chooser, and More, with Microsoft XNA Framework

WPH304 | New Windows Phone Data Access Features

WPH307 | Connecting Windows Phones and Slates to Windows Azure

WPH311 | Lessons Learned about Application Performance on Windows Phone

Windows Phone Booth after this session

Page 32: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Windows Phone Related Content Monday, May 16

WPH201: Windows Phone: What’s New?

WPH371-INT: Building a Mobile Message Queue for Windows Phone

WPH312: What’s New for Windows Phone Development with Microsoft Silverlight?

WPH302: Windows Phone Productivity Scenarios with Microsoft Exchange Server 2010 and Microsoft Office 365

WPH373: Meet the Windows Phone Application Platform Engineering Team

Page 33: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Windows Phone Related Content Tuesday, May 17

WPH308: Multi-tasking and Application Switching for Windows Phone

OSP312: Developing Microsoft Office Business Solutions that Span the PC, Windows Phone, and the Web

WPH309: Enhanced Push Notifications and Live Tiles for Windows Phone

WPH303: Understanding the Windows Phone Development Tools

COS315: Building Windows Phone Applications with the Windows Azure Platform

Page 34: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Windows Phone Related Content Tuesday, May 17

WPH305: Internet Explorer 9 on Windows Phone

OSP209 Building Your First Windows Phone Application for Microsoft SharePoint 2010

WPH203: Understanding Windows Phone Marketplace

WPH375-INT: Building Multi-tasking Enabled Windows Phone Applications

Page 35: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Windows Phone Related Content Wednesday, May 18

WPH202: Windows Phone at Microsoft

DEV317: Using Microsoft Visual Basic to Build Windows Phone Applications

WPH310: Building Your First Windows Phone Game with XNA

WPH374-INT: Hardcore Windows Phone Development Questions

DEV205: Microsoft Expression for Developers: Demystifying User Interface Design

WPH306: Building Windows Phone Applications with Microsoft Silverlight and XNA

WPH304: New Windows Phone Data Access Features

Page 36: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Windows Phone Related Content Thursday, May 19

WPH301: Deploying Windows Phone in the Enterprise

DPR303: Developing Enterprise-Grade Mobile Solutions

WPH307: Connecting Windows Phones and Slates to Windows Azure

WPH372-INT: Windows Phone Marketplace: Interactive

WPH311: Lessons Learned about Application Performance on Windows Phone

WPH311: Lessons Learned about Application Performance on Windows Phone

SIM323: User Identity and Authentication for Desktop and Phone Applications

Page 37: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Windows Phone ResourcesQuestions? Demos? The latest phones?

Visit the Windows Phone Technical Learning Center for demos and more…

Business IT resources

blogs.technet.com/b/windows_phone_4_it_pros

Developer resources

craete.msdn.com

Experience Windows Phone 7 on-line and get a backstage pass

www.windowsphone.com

Page 38: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Win a Windows Phone Contest

QUESTIONS?

Go to the WPC Information Counter

at the TLC

HAT CONTEST*

How do you enter?Enter by visiting the Windows Phone booth, accepting a free Windows Phone branded hat, and wearing that hat during the Event

How am I selected?Each day of the event, a Windows Phone representative will randomly select up to 5 people who are observed wearing their Windows Phone branded hat

SESSION CONTEST*

During each Windows Phone session the moderator will post a question; the first person to correctly answer the question and is called on by the moderator will potentially win

* Restrictions apply please see contest rules for eligibility and restrictions. Contest rules are displayed in the Technical Learning Center at the WPH info counter

Page 39: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Resources

www.microsoft.com/teched

Sessions On-Demand & Community Microsoft Certification & Training Resources

Resources for IT Professionals Resources for Developers

www.microsoft.com/learning

http://microsoft.com/technet http://microsoft.com/msdn

Learning

http://northamerica.msteched.com

Connect. Share. Discuss.

Page 40: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Complete an evaluation on CommNet and enter to win!

Page 41: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

Scan the Tag to evaluate this session now on myTech•Ed Mobile

Page 42: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.

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

Page 43: WPH310. Free Phone! Windows Phone 7 as a Game Platform Free Tools to Build Great Games The Game Loop Input on Windows Phone 7 Building a Game with Your.