Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software...

16
Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone [email protected] http://www.attido.com

Transcript of Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software...

Page 1: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

Microsoft Tech Days 2012

Cheezia: Developing a Windows Phone XNA Game

Rodrigo BarrettoSoftware Engineer - MCPD on Windows [email protected]://www.attido.com

Page 2: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

2

Agenda • Cheezia• XNA Overview• Game State Management• Input Handling• Update Method• Draw Method• Sound Effects• Configuration Files as Resources• Tombstoning• Configuring Metadata Files• References

Page 3: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

3

Cheezia • Puzzle / Reaction game• Originally developed in Flash for iOS and Android

devices using Adobe AIR• Windows Phone version:• Over 54k downloads• Featured in Channel 9’s Hot Apps• Full source code is available at

http://www.attido.com/techdays

Page 4: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

4

XNA Overview • High performance game framework• Enables creation of 2D and 3D games for Windows

Phones, Xbox 360 and PC• Provides a content pipeline that compiles game assets

into XNBs• Polling loop model instead of event driven • Provides GraphicsDeviceManager and ContentManager

Initialize

Load Content

Update

Draw

Unload Content

Page 5: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

5

Game State Management

• ScreenManager• Inherits from DrawableGameComponent• Manages one or more GameScreen instances

• Calls Update and Draw of each GameScreen instance

• Routes input to the topmost active screen• Activates / deactivates each GameScreen instance

• GameScreen

GameScreen

ActivateDeactivate

UnloadHandleInput

UpdateDraw

Page 6: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

6

Game State Management

• InputState• Reads input from keyboard, gamepad and

touchpanel

• InputAction• Evaluates which buttons and keys have been

pressed

• IScreenFactory• Instance is added to Game.Services• CreateScreen ->

Activator.CreateInstance(screenType)

Page 7: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

7

Input Handling

• ScreenManager refreshes input states in each Update• XNA supports up to 4 input points• Special button: Back• Accelerometer is event driven• Bind to ReadingChanged event and call Start• Guide.IsScreenSaverEnabled

• Guide exposes virtual keyboard: BeginShowKeyboardInput / EndShowKeyboardInput

HandleInput

InputState

Gestures TouchState

HandleInput

InputAction.Evaluate

Page 8: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

8

Update Method

• Update game variables• Speed, acceleration, position, score, timer, animations, ...

• Check for game over / level accomplished / achievement unlocked, ...

• GameTime exposes important properties• ElapsedGameTime• TotalGameTime• IsRunningSlowly

Page 9: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

9

Draw Method • Draws into the back buffer• Rendered in the next frame

• Order matters!!• Transparency from .png or Color Key property (default is

Magenta)• XNA

supports .png, .bmp, .jpg, .tga, .dds, .spritefont, .x, .fx, .fbx• Use fonts from:• The system: default is Segoe UI Mono • Own .ttf installed on development machine• .bmp file

GraphicsDevice.Clear

SpriteBatch.Begin

SpriteBatch.End

SpriteBatch.DrawSpriteBatch.DrawString

Page 10: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

10

Sound Effects • Loaded as content items• SoundEffect• Plays the sound until the end

• SoundEffectInstance provides more control:• Volume, pitch, pan• Playback capabilities

• XNA supports .wav, .mp3, .wma• XACT sound fields are not supported on the phone

Content Manager

Sound Effect

Play PlayPause

ResumeStop

Sound Effect Instance

VolumePitchPan

Page 11: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

11

Configuration Files as Resources

• Additional .xml files to configure:• Level design• Achievement related data• ...

• Corresponding classes must be implemented in a separate Game Library project

• Automatically parsed when loading via Content Manager

Page 12: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

12

Tombstoning • The player might be interrupted while playing• Needs to maintain the illusion that the game was never

interrupted• Bind to PhoneApplicationService’s events in main game

class• Launching, Activated, Deactivated, Closing

• ScreenManager takes care of activating/deactivating each screen and knows if instances were preserved (fast app switching)

• Save and load states and values of properties of each screen• Temporary data -> PhoneApplicationService’s state

dictionary• Persistent data -> Isolated Storage

CallSMS

Start ButtonSearch ButtonCamera Button

Screen Lock

Page 13: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

13

Configuring Metadata Files

• Make sure you fill them with information regarding your game• Title• Description• Author• Publisher• Version• Genre: ”Apps.Games”

Page 14: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

15

References • App Hub• http://create.msdn.com/• http://create.msdn.com/en-US/education/

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

Page 15: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.

Microsoft Tech Days 2012

Cheezia: Developing a Windows Phone XNA Game

Rodrigo BarrettoSoftware Engineer - MCPD on Windows [email protected]://www.attido.com

Page 16: Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone rodrigo.barretto@attido.com.