real life xna
TRANSCRIPT
Real life
Johan Lindfors
windows phone for games
• impressive performance
• sensors and touch
• potentially xbox-live
• ads and trials
kinectimals
harvest
implode
doodle fit
ilomilo
other favorites
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
initialize update render
managing content
• content pipeline
• import common files
• leverage compile time
• optimized binary format
• extensible
first some 2d
• x and y (and z)
• spriteBatch
• sprites/sprite sheets
• blending
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)
demo
effects - shaders
• configurable
• basic
• skinned
• environmentMap
• dualTexture
• alphaTest
demo
”hardware scaler”
• 800x480 = 384 000 pixels
• 600x360 = 216 000 pixels (56%)
• 400x240 = 96 000 pixels (25%)
graphics.PreferredBackBufferHeight = 800; graphics.PreferredBackBufferWidth = 480;
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);
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)
demo
sound and music
• soundEffect
• load as content
• wp handles 64 simultaneously
• possible to change
• pitch
• volume
• 3d location
orientation
• default is ”LandscapeLeft”
graphics.SupportedOrientations = DisplayOrientation.Portrait | DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
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(); };
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;
Accelerometer accel; private void startAccelerometer() { accel = new Accelerometer(); accel.ReadingChanged += new EventHandler <AccelerometerReadingEventArgs> (accel_ReadingChanged); accel.Start(); }
start accelerometer
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
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(); ... }
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) { ... } }
network
• http, rest, xml, sockets...
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { if (e.Error == null) { mapImage = Texture2D.FromStream( graphics.GraphicsDevice, e.Result); } }
xbox live
• avatars and “trials” available for all
• developers with agreements
• profile
• invites
• achievements
• leaderboard
• gamerServices
• contact: [email protected]
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);
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;
marketplace
• local structure
• test kit in VS2010
• updates
• auto-publish
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); }
news in mango
• silverlight + xna
• fast application switching
• profiling
• combined api for movement
demo
tripeaks solitaire
• fabrication games
• true 3D
• all code in objective-c
-(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; } }
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; } }
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; } }
demo
future of xna?
• silverlight 5.0
• subset of XNA
• focused on business apps
• windows 8
• leverages directx 11
• likely to attract commercial studios
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