41
Introduktion till Johan Lindfors

Introduktion till XNA

Embed Size (px)

DESCRIPTION

Presenation från WP7 utvecklar-dagen på Microsoft 2011-05-26

Citation preview

Page 1: Introduktion till XNA

Introduktion till

Johan Lindfors

Page 2: Introduktion till XNA
Page 3: Introduktion till XNA

windows phone för spel

• imponerande prestanda

• sensorer och ”touch”

• potentiellt xbox-live

• annonser och trials

Page 4: Introduktion till XNA

harbor master

Page 5: Introduktion till XNA

harvest

Page 6: Introduktion till XNA

tiki towers

Page 7: Introduktion till XNA

doodle fit

Page 8: Introduktion till XNA

ilomilo

Page 9: Introduktion till XNA

xna på 1 minut

• ett omfattande ramverk för spel

• integrerad hantering av innehåll

• spel med 2d och ”sprites”

• spel med 3d och ”meshes”

• gemensamma förmågor för pc, wp, xbox

Page 10: Introduktion till XNA

Initialisera Uppdatera Rita

Page 11: Introduktion till XNA

hantering av innehåll

• content pipeline

• importera vanliga filer

• optimeras till binärt format

• utbyggbart

Page 12: Introduktion till XNA

demo

Page 13: Introduktion till XNA

”hardware scaler”

• 800x480 = 384 000 pixlar

• 600x360 = 216 000 pixlar (56%)

• 400x240 = 96 000 pixlar (25%)

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

Page 14: Introduktion till XNA

generellt för prestanda

• gc är ”enklare” än på pc (för närvarande)

• allokera objekt tidigt, återanvänd

• håll reda på stack och heap

• använd inte foreach

• använd inte linq

Page 15: Introduktion till XNA

och nu lite 3d

• x, y och z

• kameran beskrivs med matriser

• vy

• projektion

• världsmatriser transformerar relativa objekt

• förflyttning

• rotation

• skalning

Page 16: Introduktion till XNA

demo

Page 17: Introduktion till XNA

effekter - shaders

• konfigurerbara

• basic

• skinned

• environmentMap

• dualTexture

• alphaTest

Page 18: Introduktion till XNA

ljud och musik

• soundEffect

• laddas som vanligt innehåll

• wp kan hantera upp till 64 samtidiga

• möjligt att förändra

• ”pitch”

• volym

• plats som ljudet spelas upp från

Page 19: Introduktion till XNA

orientering

• grundinställningen är ”LandscapeLeft”

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

Page 20: Introduktion till XNA

orientering

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 21: Introduktion till XNA

accelerometer

• mäter acceleration i X, Y och Z

• värden returneras mellan -1 och +1

• händelsebaserad

• läs värden i ”event”, lagra för användning

using Microsoft.Devices.Sensors;

Page 22: Introduktion till XNA

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

starta accelerometern

Page 23: Introduktion till 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; } }

läsa accelerometern

Page 24: Introduktion till XNA

touch

• windows phone hanterar 4 punkter

• alla punkter har unika id’n

• pressed | moved | released

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

Page 25: Introduktion till XNA

gester

• wp kan också hantera gester

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

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

Page 26: Introduktion till XNA

nätverksåtkomst

• http, rest, xml...

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

Page 27: Introduktion till XNA

xbox live

• avatarer och “trials” för alla

• för utvecklare med kontrakt

• “profile”

• “invites”

• riktiga “achievements”

• “leaderboards”

• “gamerServices”

• kontakta: [email protected]

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

Page 28: Introduktion till XNA

trial mode

• var kreativ för att driva sälj

• anrop till IsTrialMode tar 60 ms, cacha!

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

Page 29: Introduktion till XNA

annonser

• istället för att användaren betalar

• finns inte för svenska applikationer ännu*

*sanning med modifikation, det finns alternativ

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

Page 30: Introduktion till XNA

marketplace

• testa, testa, testa

• lokal struktur

• uppdateringar

• auto-publicering

Page 31: Introduktion till XNA

nyheter i och med mango

• silverlight + xna

• exekveringsmodellen

• profilering

• kombinerat api för rörelse

Page 32: Introduktion till XNA

demo

Page 33: Introduktion till XNA
Page 34: Introduktion till XNA

tripeaks solitaire

• fabrication games

• äkta 3D

• all kod i objective-c

Page 35: Introduktion till 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 36: Introduktion till 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 37: Introduktion till 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 38: Introduktion till XNA

demo

Page 40: Introduktion till XNA

så många resurser – så lite tid

• create.msdn.com

• jodegreef.wordpress.com - angry pigs

• www.xnaresources.com

• programmeramera.se

• www.infozone.se

Page 41: Introduktion till XNA