55
7 Glen Gordon Developer Evangelist http://blogs.msdn.com/glengordon @glengordon Developing WP7 apps using XNA

XNA and Windows Phone

Embed Size (px)

DESCRIPTION

How to build XNA applications for Windows Phone.

Citation preview

Page 1: XNA and Windows Phone

7

Glen GordonDeveloper Evangelisthttp://blogs.msdn.com/glengordon@glengordon

Developing WP7 apps using XNA

Page 2: XNA and Windows Phone

2 Windows Phone Microsoft confidential.

Agenda

XNA Game Studio 4.0 – Powerful, Productive, Portable

Windows Phone 7 – A new beginning

XNA Framework

- Game Loop, Graphics, Audio, Media, Touch, Sensors

XBOX Live

Q & A

Page 3: XNA and Windows Phone

3 Windows Phone Microsoft confidential.

Games Hub Featuring Xbox LIVE

Page 4: XNA and Windows Phone

Xbox LIVE is Gaming Services

Windows Phone will extend the Xbox LIVE brand beyond the console for the first timeWindows Phone is the first step towards our vision of a ubiquitous gaming service

Differentiates your title from the rest

Gamertag

Friends

AchievementsMerchandising Premium Placement

Page 5: XNA and Windows Phone

Game Development Opportunities

Without Xbox LIVE You can still write

and publish games for Windows Phone

Create great games for marketplace

http://developer.windowsphone.com

We’re interested in your great games!

[email protected]

To use the great features of Xbox

LIVE

Find a publisher!Lots to choose from!

Page 6: XNA and Windows Phone

Consistent sets of hardware capabilities defined by Microsoft

Windows Phone 7 Hardware

ResolutionTouch InputCPU / GPURAM

Hardware keyboard is optional

Page 7: XNA and Windows Phone

User Experience Frameworks

Modern XAML/event-driven application UI frameworkRapid creation of visually rich appsHTML/JavascriptMature, robust, widely deployed technology

High performance game frameworkRapid creation of multi-screen 2D and 3D games Rich content pipelineMature, robust, widely adopted technology spanning Xbox, Windows, and Zune

GAMES(and applications)

APPLICATIONS(and games)

Page 8: XNA and Windows Phone

Powerful

Productive

Portable

Page 9: XNA and Windows Phone

XNA Game StudioMakes game development easier

XNA Framework provides robust APIs for games

C#, .NET and Visual Studio tooling

Solutions for game content processing

Not an engine solution

Creating Games

Page 10: XNA and Windows Phone

XNA Game Studio 4.0

Develop for

Windows Phone 7 Simplified

graphics API’s

Visual Studio 2010 integration

Enhanced audio

support

New configurable

effects

Page 11: XNA and Windows Phone

Powerful

Page 12: XNA and Windows Phone

Uses the .NET platform

Managed Code for Game Development

Windows Phone 7

Managed code platform, no unsafe code

XNA Game Studio 4.0 is C# exclusive

800+ managed code games on XBLA/XBLIG

Windows games published

through portals

.NET/XNA is used for games today!

[email protected]

Page 13: XNA and Windows Phone

Frameworks designed

for performance

Addressing Performance Head-on

Frameworks designed

for performance

Frameworks designed

for performance

Frameworks designed

for performance

XNA Framework designed for

gaming scenarios

Commitment to future

of managed code

No unnecessary garbage generation

Math libraries optimized

Efficient APIs with tuned transitions to native code

Three + years of profiling

and investment

We’ve built for performance on Windows

Phone 7

Page 14: XNA and Windows Phone

http://xbox.com/phone

Page 15: XNA and Windows Phone

Demo: Primitives3D

Page 16: XNA and Windows Phone

Productive

Page 17: XNA and Windows Phone

Windows Phone Microsoft confidential.

Visual Studio and .NET Productive development with .NET and C# High performance IDE Intellisense makes coding faster Integrated build/deploy/debug experience MSBuild engine for build automation

Page 18: XNA and Windows Phone

18 Windows Phone Microsoft confidential.

Content PipelineSimplify Your Content Usage!

Importers for common game data formats

Manage assets in Visual Studio

Optimize data into binary format for

efficient loading Fully extensible

Content projects external in XNA Game

Studio 4.0

Page 19: XNA and Windows Phone

19 Windows Phone Microsoft confidential.

Simplifying Game Development

XNA Framework

Page 20: XNA and Windows Phone

The XNA Framework Game Loop is layered on top of the Silverlight Application object on Windows Phone 7

Provides the bulk of integration of API’sMost of the XNA Framework can be accessed from Silverlight applications

Including Gamer Services (Xbox LIVE)

In this release some sharing/composition is not complete

Scenes using GraphicsDevice from XNA Framework and UIElements from Silverlight

You’ll want to choose the technology that works best for your scenarios

Bridging the Gap

Page 21: XNA and Windows Phone

GraphicsUI control heavy consider SilverlightDesire vector graphics in XAML

Media Rich video support in application

ToolingIf you use Microsoft Blend in your pipeline

Choosing the Right Technology

Page 22: XNA and Windows Phone

GraphicsUsing 3D graphicsSprite heavy 2D applications should consider the XNA Framework Game Loop

Simulation/DrawingThose who prefer a traditional update/draw/present frame loop

ToolingThose who want to use the XNA Framework Content Pipeline graphics types

Leveraging the Right Technology

Page 23: XNA and Windows Phone

XNA Framework Game Loop Example

System integration with Windows Phone 7 best practices

Translated to existing XNA Framework concepts

Traditional update/draw/present frame loop

Core programming model consistent with previous releasesChanges implemented yield better power performance on devices

XNA Framework Game Loop 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);}

Start simple and customize!

Page 24: XNA and Windows Phone

Demo: Game Loop

Page 25: XNA and Windows Phone

25 Windows Phone Microsoft confidential.

Graphics

Page 26: XNA and Windows Phone

Graphics Overview

Evolution of our existing immediate mode rendering API

Simplifies for resource and render state management

Feature segmentation between “Reach”/“HiDef” profiles

Rendering primitives 2D and 3D

Page 27: XNA and Windows Phone

Configurable Effects

New configurable effect

classes on all platforms

BasicEffect

SkinnedEffect

EnvironmentMapEffect

DualTextureEffect

AlphaTestEffect

Custom effects not available on Windows

Phone 7

Page 28: XNA and Windows Phone

System Support: Scaler and Orientation

Write your game without worrying about native resolution or orientation

Automatic rotation between portrait and landscapeTouch automatically supports both scale and orientation changes

Scaler can drastically improve performanceTrade off performance for “crispness” and shade fewer pixels800x480 = 384,000 pixels, 480x320 = 153,600 pixels

Upsample an arbitrary back buffer to native device resolutionFar higher quality than bilinear filteringAllows for easier porting from other platforms

Scaling/Rotation comes for “free” from Hardware

Page 29: XNA and Windows Phone

Demo: ReachDemo

Page 30: XNA and Windows Phone

30 Windows Phone Microsoft confidential.

Can you hear me now?

Audio & Media

Page 31: XNA and Windows Phone

Audio Capture Example

Audio public void EventDrivenCapture(){ mic = Microphone.Default; buffer = new byte[mic.GetSampleSizeInBytes(mic.BufferDuration)]; mic.BufferReady += new EventHandler(OnBufferReady); DynamicPlayback = new DynamicSoundEffectInstance(mic.SampleRate, AudioChannels.Mono);}

public void OnBufferReady(object sender, EventArgs args){ // Get the latest captured audio. int duration = mic.GetData(buffer);

// Do some post-capture processing and playback. MakeMeSoundLikeARobot(buffer, duration); DynamicPlayback.SubmitBuffer(buffer);}

Audio Capture and Playback

Simple API to play back WAV data

Modify pitch, volume, pan audio

Ability to play synthesized/buffered audio

Serialize captured data

Provides more control over System.Media types on Windows Phone 7

Microphone/Bluetooth SupportPlayback through headset

Capture through mic or headset

Audio Playback Example// Load a sound effect from a raw streamSoundEffect effect1 = SoundEffect.FromStream(GetStreamFromTheWeb("http://url.wav"));effect1.Play();

// Create dynamic audio on the flybyte[] fluteSound = GetFluteNote();effect2 = new SoundEffect(fluteSound, SampleRate, AudioChannels.Stereo);SoundEffectInstance instance = effect2.CreateInstance();instance.Pan = -1; instance.Pitch = 1.5f;instance.Play();

Page 32: XNA and Windows Phone

URI Song Playback Example

Retrieve Image Data

Music Enumeration and Playback

Media – Music/Photos/Video// Constructs a song from a URI

Uri mediaStreamUri = new Uri("http://song.asx");Song streamedSong = Song.FromUri("Song",

mediaStreamUri);

// Play the songMediaPlayer.Play(streamedSong);

MediaLibrary media = new MediaLibrary();

// Get the JPEG image dataStream myJpegImage = ReadAndModifyPicture(somePicture);

// Save texture to Media Library   media.SavePicture("Awesome", myJpegImage);

Picture Enumeration and Playback

Video Playback

Control and enumerate users’ media within a game

Ability to play songs from URI/URL (i.e. music app)

Supports photo picking/editing/publishing

Uses standard video player API

Show/Hide controls

Page 33: XNA and Windows Phone

Demo: Calling XNA Audio from Silverlight

Page 34: XNA and Windows Phone

34 Windows Phone Microsoft confidential.

Interacting with games gets easier!

Input / Touch

Page 35: XNA and Windows Phone

Touch Input Handling

Cross Platform Input API

Touch API

Xbox 360 Controllers (Xbox/Windows)

Keyboard (Xbox/Windows/Windows Phone 7)

Available across platforms for portability (fewer #ifdefs)

Multipoint on Windows Phone 7 and Windows

Orientation and resolution aware

Developer can override

Input Overview

var touchCollection = TouchPanel.GetState();

//...

foreach (var touchLocation in touchCollection){ if (touchLocation.State == TouchLocationState.Released) { //... }}

Page 36: XNA and Windows Phone

36 Windows Phone Microsoft confidential.

For Silverlight and XNA Framework

Sensors

Page 37: XNA and Windows Phone

Accelerometer Example

VibrationExample

Leverage Platform Features on Windows Phone 7

Location

Accelerometer

Vibration

Sensor Overview

Accelerometer accelerometer = new Accelerometer();

accelerometer.ReadingChanged +=

AccelerometerReadingChanged;

accelerometer.Start();

VibrateController rumbler;rumbler.Start(TimeSpan.FromSeconds(2));

Page 38: XNA and Windows Phone

Demo: Asteroids Accelerometer

Page 39: XNA and Windows Phone

39 Windows Phone Microsoft confidential.

Xbox LIVE

Page 40: XNA and Windows Phone

Connectivity at a GlanceWindows Phone 7 OS

Xbox LIVE

Gamer Services

HTTP

Invites

ProfileAchieve-ments

Leader-boards

TrialMode

Push

Avatars

Page 41: XNA and Windows Phone

Windows Phone Microsoft confidential.

Profile Your Identity in the Cloud

Your phone knows you by your Windows Live ID

Link to your Gamertag

Page 42: XNA and Windows Phone

ProfileRead a Player’s Profile

// Profile accessSignedInGamer gamer = Gamer.SignedInGamers[0];

// Get the player's GamerTag to displaystring gamerTag = gamer.Gamertag;

// A SignedInGamer has a ProfileGamerProfile profile = gamer.GetProfile();

// Get the player's current GamerScoreint gamerScore = profile.GamerScore;

// get the gamer picture (PNG file stream)Stream gamerPictureStream = profile.GamerPicture;

Page 43: XNA and Windows Phone

Achievements Award an Achievement

// Award an achievementSignedInGamer gamer = Gamer.SignedInGamers[0];gamer.AwardAchievement("Attended TechEd 2010");

Read Achievements// Get achievementsAchievementCollection achievements = gamer.GetAchievements();

// walk through achievementsforeach (Achievement a in achievements){

string name = a.Name;string description = a.Description;bool earned = a.IsEarned;int score = a.GamerScore;

Stream icon = a.Picture; }

Real achieventments Real gamerscore Up to 20 awards,

200G total Dead simple API,

deep game design

Page 44: XNA and Windows Phone

Leaderboards Write to a Leaderboard

// Create leaderboard identity with game mode 1LeaderboardIdentity id = LeaderboardIdentity.Create(LeaderboardKey.BestScoreLifeTime, 1);

// get the leaderboard writer from the signed in gamerLeaderboardWriter writer = gamer.LeaderboardWriter;

// get the leaderboard entry for the identityLeaderboardEntry entry = writer.GetLeaderboard(id);

// write new leaderboard dataentry.Rating = 1000;entry.columns.SetValue("Outcome", LeaderboardOutcome.Win);

Read From a Leaderboard// Read from leaderboard with page size of 10LeaderboardReader reader = LeaderboardReader.Read(id, gamer, 10);

foreach (LeaderboardEntry e in reader.Entries){

// score or time, as defined by identity. Rating determines rank.long rating = e.Rating;// read additional column datalong wins = e.Columns.GetValueInt64("Wins");Stream blob = e.Columns.GetValueStream("Blob");

}

reader.PageDown();

Compete withFriends

Score- or Time-based

Fixed columns 10k blob data Pivot on gamer

Page 45: XNA and Windows Phone

Trial Mode

Trial ModeGuide.SimulateTrialMode = true;

// if we are in trial mode, show a marketplace offeringif (Guide.IsTrialMode){

PlayerIndex playerIndex = Gamer.SignedInGamers[0].PlayerIndex;Guide.ShowMarketplace(playerIndex);

}

Simple check Simulate for testing Send user to your Marketplace offer

Page 46: XNA and Windows Phone

Avatars

http://avatar.xboxlive.com/avatar/Major%20Nelson/avatar-body.png

Currently supported through web service only

Static pose rendered on LIVE back-end Download as a stream

Page 47: XNA and Windows Phone

Game Invites Game invites are handled through email Guide.ShowGameInvite() invokes

platform picker UI Player chooses game invite recipients Friends see invitations in their games hub

Page 48: XNA and Windows Phone

48 Windows Phone Microsoft confidential.

Portable

Page 49: XNA and Windows Phone

XNA Framework designed to be cross platform

Smaller time investment and target more sockets

Project synchronization between platforms

Target Three Screens

Page 50: XNA and Windows Phone

XNA Framework ProfilesCreate a clear development environmentTarget broadly or platform showcases

HiDef

Reach Designed for compatibility across screens/devicesThis profile includes Windows Phone 7

Platform showcase featuresXbox 360/Windows Only

Page 51: XNA and Windows Phone

SummaryPowerful

Productive

Portable

Great managed code games, working todayWindows Phone provides a powerful platform for gaming

Focus on being a game developerGreat tools make you more productive

Target more platforms easilyFocus on your game differences, not the technology

Page 52: XNA and Windows Phone

Call to ActionDownload the Windows Phone Developer Tools

http://developer.windowsphone.com

Create awesome games!

Page 53: XNA and Windows Phone

Additional Resources

Hundreds of samples

Lots of MVPs and experts to help you get started

XNA Creators Club @ http://creators.xna.com

Team Blog @ http://blogs.msdn.com/xna/

Shawn Hargreaves @ http://blogs.msdn.com/shawnhar/ (Great Tech Info!)

Email: [email protected]

On the web: http://developer.windowsphone.com

Peer Support @ http://forums.xna.com

BlogsContact

Microsoft

Page 54: XNA and Windows Phone

Q&A and Break

Page 55: XNA and Windows Phone

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