md2010 jl-wp7-sl-game-dev

37
Zagreb, 23. rujna 2010.

Upload: jose-millas

Post on 11-Jan-2015

27.054 views

Category:

Technology


0 download

DESCRIPTION

Introduction to windows phone 7 game development with Silverlight - for the demos please check http://silverlightguy.com

TRANSCRIPT

Page 1: Md2010 jl-wp7-sl-game-dev

Zagreb, 23. rujna 2010.

Page 2: Md2010 jl-wp7-sl-game-dev

Developing WP7 Apps with Silverlight

José Luis LatorreMicrosoft MVP, UX Specialist & Brainsiders CEOhttp://silverlightguy.com

Page 3: Md2010 jl-wp7-sl-game-dev
Page 4: Md2010 jl-wp7-sl-game-dev

Generalni sponzori:

Glavni sponzori:

Sponzori:

Organizatori:

Medijski sponzori: Strateški partneri:

Službena PR agencija:

Generalni medijski sponzor:

Page 5: Md2010 jl-wp7-sl-game-dev

GAMES WITH SILVERLIGHT? WHY?

Page 6: Md2010 jl-wp7-sl-game-dev

Silverlight is for games?

• Concretely, Silverlight is good for casual games that doesn’t require intensive graphic capabilities.

• We have the fact that:– Players love casual games (simple & easy to pick up

and put down).– Phone platforms are great for this– Silverlight is great for this.

Page 7: Md2010 jl-wp7-sl-game-dev

Why Silverlight

• Compelling Cross-Platform User Experience• Flexible object-oriented model– Fully managed code to improve encapsulation and

centralization• Declarative presentation language (Xaml)• Role specific tools• Rapid application development • Good performance

Page 8: Md2010 jl-wp7-sl-game-dev

What kind of games?

• Word games• Desk games• Turn based strategy games• Pictorial games• Platform games• Touch interaction games• If this is what you want to write there might be

no need to learn XNA..

Page 9: Md2010 jl-wp7-sl-game-dev

THE GAME LOOP

Page 10: Md2010 jl-wp7-sl-game-dev

Game Loop I

•The “GAME LOOP”• Executes once per frame• It handles all the game logic, animation, Collisions, manages

input, applies game logic, etc.• Optimal game loop in Silverlight is usually implemented with CompositionTarget.Rendering, which executes once per rendered frame.•Final Hardware will execute 30 Frames Per Second

•For details on deciding the Game Loop implementation, check http://nokola.com/ and its ”GameLoopsInSilverlight.docx” document.

Page 11: Md2010 jl-wp7-sl-game-dev

Game Loop II

• Is the ”Heart Beat” of the game...• Typical game loop logic

1. Checks for user input2. Checks for collisions3. Updates all the game elements visuals4. Draws all game elements (Actually not needed in

Silverlight due to the Visual Tree Model)5. Applies Game logic & AI.

Page 12: Md2010 jl-wp7-sl-game-dev

Game loop III

protected DateTime lastTick; public Page(){ InitializeComponent(); CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); lastTick = DateTime.Now;}

void CompositionTarget_Rendering(object sender, EventArgs e){ DateTime now = DateTime.Now; TimeSpan elapsed = now - lastTick; lastTick = now;

//Game Logic goes here}

Page 13: Md2010 jl-wp7-sl-game-dev

Sprites

• The game characters can be represented by Sprites, which are usually represented by an image and a position on the game surface.

• So they have:1. Image.2. Position.3. Vector of movement.4. Other details, depending on the game.

Page 14: Md2010 jl-wp7-sl-game-dev

Animated Sprites

• An animated sprite is the natural evolution as it can show an animation instead of a still image, which is good if the player is walking, to show a walking animation.

• So they have, additionally from the Sprite:1. An animation or sequence of images, also called

Frames.2. Speed of the animation ( frames per second)3. Number of Frames.

Page 15: Md2010 jl-wp7-sl-game-dev

Game character

• A game character derives from a sprite or animated sprite and represents a game element, the player, an enemy, bonus, obstacle, etc..

• It usually has its own logic and is tied to events that determine its behavior.

Page 16: Md2010 jl-wp7-sl-game-dev

Sprite, Camera, Action(link to demo)

Note: This demo is derived from a sample from Andy Bealieu.

Page 17: Md2010 jl-wp7-sl-game-dev

Collisions I

• If two sprites (or animated sprites) collide, for example the player and a enemy, something must happen!!

• For this, we must know if there is a collision between both sprites.

• Usually a calculation of the bounding boxes will be enough.

Page 18: Md2010 jl-wp7-sl-game-dev

Collisions II

• First, we need the bounding boxes of the two elements we want to discover if they have collided:

public static Rect UserControlBounds(FrameworkElement control){Point ptTopLeft = new Point(Convert.ToDouble(control.GetValue(Canvas.LeftProperty)), Convert.ToDouble(control.GetValue(Canvas.TopProperty)));

Point ptBottomRight = new Point(Convert.ToDouble(control.GetValue(Canvas.LeftProperty)) + control.Width, Convert.ToDouble(control.GetValue(Canvas.TopProperty)) + control.Height);return new Rect(ptTopLeft, ptBottomRight);}

Page 19: Md2010 jl-wp7-sl-game-dev

Collisions III

• Next we validate if both bounding boxes overlap each other:

public static bool RectIntersect(Rectangle rectangle1, Rectangle rectangle2){ return (((double)rectangle1.GetValue(Canvas.LeftProperty) <= (double)rectangle2.GetValue(Canvas.LeftProperty) + rectangle2.Width) && ((double)rectangle1.GetValue(Canvas.LeftProperty) + rectangle1.Width >= (double)rectangle2.GetValue(Canvas.LeftProperty)) && ((double)rectangle1.GetValue(Canvas.TopProperty) <= (double)rectangle2.GetValue(Canvas.TopProperty) + rectangle2.Height) && ((double)rectangle1.GetValue(Canvas.TopProperty) + rectangle1.Height >= (double)rectangle2.GetValue(Canvas.TopProperty)));}

Page 20: Md2010 jl-wp7-sl-game-dev

INPUT

Page 21: Md2010 jl-wp7-sl-game-dev

Input via Buttons

Back – Start – Search Only

NOT usable for Games!

Page 22: Md2010 jl-wp7-sl-game-dev

Input via Touch

•UIElement Class contains Events• ManipulationStarted• ManipulationDelta• ManipulationCompleted

•Supported in Emulator• Requires Multitouch Monitor

Page 23: Md2010 jl-wp7-sl-game-dev

1

Input via Accelerometer

Measures force applied on each axis over time

+Y

-Y

+X-X

+Z

-Z• Not supported by Emulator

• Can be faked using Mouse Input + Perspective Transform

Page 24: Md2010 jl-wp7-sl-game-dev

All together now!! – A shooting game(link to demo)

Note: This demo is derived from a great sample from Matthew Casperson.

Page 25: Md2010 jl-wp7-sl-game-dev

OTHER POINTS

Page 26: Md2010 jl-wp7-sl-game-dev

Performance Statistics

• Set EnableFrameRateCounter = true

A – Render Thread FramerateB – UI Thread FramerateC – Amount of Video Memory UsedD – Total # of Textures UsedE – Total # of Intermediate Textures Used

• Set EnableCacheVisualization = true• Tinted items are NOT being cached by GPU

Page 27: Md2010 jl-wp7-sl-game-dev

Automatic GPU Acceleration

• Automatically Applied to • StoryBoard Animations• Perspective 3D (PlaneProjections) – but only if they

are applied by Storyboard animations.• Uses Video Card for Transform, Rotate, Scale, Rectangular Clip

• NOT automatic for Procedural Animation!

Page 28: Md2010 jl-wp7-sl-game-dev

MONETIZATION

Page 29: Md2010 jl-wp7-sl-game-dev

MonetizationThe Marketplace Hub

Page 30: Md2010 jl-wp7-sl-game-dev

Try and buyDetailed product descriptionScreen shotsReviews & ratingsRelated appsOptional game content ratingMore apps by developer

Monetization

Page 31: Md2010 jl-wp7-sl-game-dev

Monetization70% revenue share

Trial API

Credit card & mobile operator billing

Paid, ad funded and free apps

Page 32: Md2010 jl-wp7-sl-game-dev

Deployment Process

Develop & Debug

Submit& Validate

Certify & Sign

Windows Phone Application Deployment Service

Marketplace

Page 33: Md2010 jl-wp7-sl-game-dev

RESOURCES

Page 36: Md2010 jl-wp7-sl-game-dev