real life xna

48

Upload: johan-lindfors

Post on 06-May-2015

893 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Real life XNA
Page 2: Real life XNA

Real life

Johan Lindfors

Page 3: Real life XNA
Page 4: Real life XNA

windows phone for games

• impressive performance

• sensors and touch

• potentially xbox-live

• ads and trials

Page 5: Real life XNA

kinectimals

Page 6: Real life XNA

harvest

Page 7: Real life XNA

implode

Page 8: Real life XNA

doodle fit

Page 9: Real life XNA

ilomilo

Page 10: Real life XNA

other favorites

Page 11: Real life XNA

xna in 1 minute

• a comprehensive framework for games

• integrated management of content

• games with 2d and ”sprites”

• games with 3d and ”meshes”

• shared features for pc, wp, xbox

Page 12: Real life XNA

initialize update render

Page 13: Real life XNA

managing content

• content pipeline

• import common files

• leverage compile time

• optimized binary format

• extensible

Page 14: Real life XNA

first some 2d

• x and y (and z)

• spriteBatch

• sprites/sprite sheets

• blending

Page 15: Real life XNA

and then some 3d

• x, y and z

• camera is described with matrices

• view

• projection

• world matrix transforms objects relatively

• movement (translation)

• rotation

• size (scale)

Page 16: Real life XNA

demo

Page 17: Real life XNA

effects - shaders

• configurable

• basic

• skinned

• environmentMap

• dualTexture

• alphaTest

Page 18: Real life XNA

demo

Page 19: Real life XNA

”hardware scaler”

• 800x480 = 384 000 pixels

• 600x360 = 216 000 pixels (56%)

• 400x240 = 96 000 pixels (25%)

graphics.PreferredBackBufferHeight = 800; graphics.PreferredBackBufferWidth = 480;

Page 20: Real life XNA

performance tips

• manage the stack and heap

• reference types live on the _______!

• value types live on the _______!

• pass large structures by reference

• don’t foreach or linq (know code cost)

Matrix a, b, c; c = Matrix.Multiply(a, b); // copies 192 bytes! Matrix.Multiply(ref a, ref b, out c);

Page 21: Real life XNA

performance tips

• gc is ”simpler” than on pc

• allocate objects early, reuse

• GC.Collect() can be your friend!

• after load, while paused

• cpu or gpu based?

• you can go up to 60 fps (60 hz)

Page 22: Real life XNA

demo

Page 23: Real life XNA

sound and music

• soundEffect

• load as content

• wp handles 64 simultaneously

• possible to change

• pitch

• volume

• 3d location

Page 24: Real life XNA

orientation

• default is ”LandscapeLeft”

graphics.SupportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;

Page 25: Real life XNA

orientation

Window.OrientationChanged += (s, e) => { switch (Window.CurrentOrientation) { case DisplayOrientation.Portrait: graphics.PreferredBackBufferHeight = 800; graphics.PreferredBackBufferWidth = 480; break; default: graphics.PreferredBackBufferHeight = 480; graphics.PreferredBackBufferWidth = 800; break; } graphics.ApplyChanges(); };

Page 26: Real life XNA

accelerometer

• measures acceleration in X, Y and Z

• values returned between -1 and +1

• event based

• read values in event, store for usage

using Microsoft.Devices.Sensors;

Page 27: Real life XNA

Accelerometer accel; private void startAccelerometer() { accel = new Accelerometer(); accel.ReadingChanged += new EventHandler <AccelerometerReadingEventArgs> (accel_ReadingChanged); accel.Start(); }

start accelerometer

Page 28: Real life XNA

Vector3 accelReading; void accel_ReadingChanged(object sender, AccelerometerReadingEventArgs e) { lock (this) { accelReading.X = (float)e.X; accelReading.Y = (float)e.Y; accelReading.Z = (float)e.Z; } }

read the accelerometer

Page 29: Real life XNA

touch

• windows phone handles 4 touch points

• all points have unique id

• pressed | moved | released

TouchCollection touches; protected override void Update(GameTime gt) { touches = TouchPanel.GetState(); ... }

Page 30: Real life XNA

gestures

• wp can also handle gestures

• tap | drag | hold | flick | pinch ...

TouchPanel.EnabledGestures = GestureType.Flick; while (TouchPanel.IsGestureAvailable) { GestureSample g = TouchPanel.ReadGesture(); if (g.GestureType == GestureType.Flick) { ... } }

Page 31: Real life XNA

network

• http, rest, xml, sockets...

void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { if (e.Error == null) { mapImage = Texture2D.FromStream( graphics.GraphicsDevice, e.Result); } }

Page 32: Real life XNA

xbox live

• avatars and “trials” available for all

• developers with agreements

• profile

• invites

• achievements

• leaderboard

• gamerServices

• contact: [email protected]

Page 33: Real life XNA

trial mode

• call to IsTrialMode takes 60 ms, cache!

• be creative in feature set

• trial or free light?

#if DEBUG Guide.SimulateTrialMode = true; #endif bool isTrial = Guide.IsTrialMode; ... Guide.ShowMarketplace(PlayerIndex.One);

Page 34: Real life XNA

ads

• instead of user paying for app

• not for swedish apps yet*

*not from Microsoft that is, there are options

using Microsoft.Advertising.Mobile.Xna; ... AdManager adManager; Ad bannerAd;

Page 35: Real life XNA

marketplace

• local structure

• test kit in VS2010

• updates

• auto-publish

Page 36: Real life XNA

protect yourself

• ready for obfuscation?

public void d(bp.b A_0) { this.l = A_0; this.i = new List<string>(); this.i.Add(am.a().e("SK_NO")); this.i.Add(am.a().e("SK_YES")); this.g = bo.a; SignedInGamer.SignedIn += new EventHandler<SignedInEventArgs>(this.d); }

Page 37: Real life XNA
Page 38: Real life XNA

news in mango

• silverlight + xna

• fast application switching

• profiling

• combined api for movement

Page 39: Real life XNA

demo

Page 40: Real life XNA

tripeaks solitaire

• fabrication games

• true 3D

• all code in objective-c

Page 41: Real life XNA

-(BOOL) animate { if([self animation] == nil) { [self draw]; return NO; } else { BOOL animationDone = [[self animation] animate]; [self draw]; if (animationDone) { x += [[self animation] currentX]; y += [[self animation] currentY]; z += [[self animation] currentZ]; rotation += [[self animation] currentRotation]; [animations removeObjectAtIndex:0]; } return animationDone; } }

Page 42: Real life XNA

public bool Animate() { if (this.Animation == null) { this.Draw(); return false; } else { bool animationDone = this.Animation.Animate(); this.Draw(); if (animationDone) { x += this.Animation.CurrentX; y += this.Animation.CurrentY; z += this.Animation.CurrentZ; rotation += this.Animation.CurrentRotation; animations.RemoveAt(0); } return animationDone; } }

Page 43: Real life XNA

public bool Animate(GraphicsDevice graphics, BasicEffect effect) { if (this.Animation == null) { this.Draw(graphics, effect); return false; } else { bool animationDone = this.Animation.Animate(); this.Draw(graphics, effect); if (animationDone) { x += this.Animation.CurrentX; y += this.Animation.CurrentY; z += this.Animation.CurrentZ; rotation += this.Animation.CurrentRotation; animations.RemoveAt(0); } return animationDone; } }

Page 44: Real life XNA

demo

Page 45: Real life XNA

future of xna?

• silverlight 5.0

• subset of XNA

• focused on business apps

• windows 8

• leverages directx 11

• likely to attract commercial studios

Page 47: Real life XNA

resources

• create.msdn.com

• jodegreef.wordpress.com - angry pigs

• www.xnaresources.com

• http://msdn.microsoft.com/en-

us/library/bb417503(XNAGameStudio.41).aspx

• programmeramera.se

• www.coderox.se

Page 48: Real life XNA