ymtis workshop geneva introduction to xna marios karagiannis

22
YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

Upload: juro

Post on 23-Feb-2016

46 views

Category:

Documents


0 download

DESCRIPTION

YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis. mkaragia @ xboxlive. My name is Marios Karagiannis I am Greek I am not affiliated with Microsoft PhD Candidate @ UNIGE In my last year Gamer Since the Game & Watch era Games Developer - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

YMTIS WorkshopGeneva

Introduction to XNAMarios Karagiannis

Page 2: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Who am I

*My name is Marios Karagiannis* I am Greek* I am not affiliated with Microsoft* PhD Candidate @ UNIGE

* In my last year*Gamer

* Since the Game & Watch era*Games Developer

* Made my first game on an8-bit Atari 65 XE (on cassette)

* Currently making games for Windows Phone 7

MKARAGIA@XBOXLIVE

Page 3: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*WP7 Hardware

*All Windows Phone 7 phones must have as a minimum (called Chassis 1):* 4 points multi touch capacitive screens* 480x800 screen resolution* 1GHz CPU* Accelerometer* 256MB Ram – 8GB Storage* DirectX 9 GPU with video acceleration* 5 MP Camera with flash* A-GPS* Compass* Ambient and proximity sensors* 3 hardware keys (Back, Start, Search)

Page 4: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*XNA

*What is XNA?*A set of tools specifically designed for game

development*Managed runtime environment* For* Windows Phone* XBOX 360* Windows

* (using almost the same code)*Originally for the XBOX it was called Xbox New

Architecture) *After XBOX 360 it means XNA is Not an Acronym

Page 5: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Is it any good?

*Let me state this*Developing games with XNA is the best way to

develop games in any platform, ever(did I say ever?)

*Why?*C#* .NET*Free and great tools (XNA Game Studio 4 and Visual

Studio Express 2010)*Great libraries*Amazing documentation

Page 6: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*XNA for Windows Phone 7

*Game loop vs event driven programming*Games play even when you don’t

Update Draw

Page 7: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Game timing

*XNA lets you choose how you want timing to work in your game:*Fixed Time Step (default)

TargetElapsedTime = TimeSpan.FromSeconds(1/30.0);

Update Draw

NOYES

IsRunningSlowly = true

Time for

next update

Page 8: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Game timing

*XNA lets you choose how you want timing to work in your game:*Variable Time Step

Be careful to use ElapsedGameTime (more traditional way to develop games)

Update Draw

Page 9: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Content

*XNA provides a powerful content pipeline that can import and process:* Images (bmp, dib, hdr, jpg, pfm, png, ppm, tga)* Fonts (converted automatically to spritefonts)*XML* 3D models(fbx)*Music (mp3, wma)* Sounds (wav)*And custom processors (if you so wish)

*Assets are processed to xbl files*Some assets can be compressed

Page 10: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Physics

*Although technically not part of the XNA you can easily compile and use the Farseer Physics Engine with your Windows Phone 7 gameshttp://farseerphysics.codeplex.com/

Page 11: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Drawing (2D and 3D)

* One Draw method* You can render 3D objects and then 2D objects

* Or vice versa* GPU hardwalre image scaler is free to use

* The scaler is easy to use: just set graphics.PreferredBackBufferWidth and PreferredBackBufferHeight in your game constructor

* The resolution can be anywhere from 240x240 up to a max of 800x480 (or 480x800 if you are making a portrait game)

* If you choose a resolution that does not match the screen aspect ratio, it will be automatically letterboxed (black bars along the edges)

* Touch input is automatically scaled to match your chosen backbuffer resolution

* Scaling is implemented by dedicated hardware, so doesn't cost any GPU* Scaling uses a high quality filter (better looking than GPU bilinear

filtering)

Page 12: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Events

*Like in Silverlight, events can occur in XNA

#if WINDOWS_PHONEPhoneApplicationService.Current.Launching+=Current_Launching;PhoneApplicationService.Current.Deactivated+=Current_Deactivating;PhoneApplicationService.Current.Activated+=Current_Activating;

#endif

Page 13: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Sensors

*With XNA you have control over*The vibration function*The accelerometer*The touch screen*The camera

*But not (yet)*The compass*The light and proximity sensors*Bluetooth

Page 14: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Let’s see how easy it is

When you start a new Windows Phone 7 XNA Game everything is setup for you:Your Game classA spriteBatch object to draw spritesYour Graphics Devide Manager objectYour Content rootYour Initialize functionYour LoadContent functionYour UnloadContent functionYour Update functionYour Draw function Update Draw

Start

Initialize

LoadContent

UnloadContent

Finish

Page 15: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*A few examples

*How to use multi touch*Touch can detect Pressed, Moved, Released

events*Is arranged in touch collections with unique

IDs// Process touch events TouchCollection touchCollection = TouchPanel.GetState(); foreach (TouchLocation tl in touchCollection) {

if ((tl.State == TouchLocationState.Pressed) || (tl.State == TouchLocationState.Moved)) { // add sparkles based on the touch location sparkles.Add(new Sparkle(tl.Position.X, tl.Position.Y, tl.Id)); }

}

Page 16: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*A few examples

*How to use the accelerometer*Use a ReadingChanged event*Read 3 axis data

Page 17: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*A few examples

Accelerometer accelSensor; Vector3 accelReading = new Vector3();

public void AccelerometerReadingChanged(object sender, AccelerometerReadingEventArgs e) {

accelReading.X = (float)e.X; accelReading.Y = (float)e.Y; accelReading.Z = (float)e.Z;

}

accelSensor = new Accelerometer(); // Add the accelerometer event handler to the accelerometer sensor. accelSensor.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(AccelerometerReadingChanged);

// Start the accelerometer try {

accelSensor.Start(); accelActive = true;

} catch (AccelerometerFailedException e) {

// the accelerometer couldn't be started. No fun! accelActive = false;

} catch (UnauthorizedAccessException e) {

// This exception is thrown in the emulator-which doesn't support an accelerometer. accelActive = false;

}

Page 18: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*A few examples

// Start the accelerometer try {

accelSensor.Start(); accelActive = true;

} catch (AccelerometerFailedException e) {

// the accelerometer couldn't be started. No fun! accelActive = false;

} catch (UnauthorizedAccessException e) {

// This exception is thrown in the emulator-which doesn't support an accelerometer. accelActive = false;

}

if (accelActive) {

// accelerate the sparkle depending on accelerometer // action. s.speed.X += accelReading.X * ACCELFACTOR; s.speed.Y += -accelReading.Y * ACCELFACTOR;

}

Page 19: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*A few examples

//When the game is paused or accelerometer data is not needed// Stop the accelerometer if it's active. if (accelActive)

{ try

{ accelSensor.Stop();

} catch (AccelerometerFailedException e)

{ // the accelerometer couldn't be stopped now.

} }

Page 20: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*Where to start

*The App Hubhttp://developer.windowsphone.com/

*Windows Phone 7 Developer Training Kithttp://create.msdn.com/en-US/education/catalog/article/wp7_training_kit

*Windows Phone 7 Jump Starthttp://create.msdn.com/en-US/education/catalog/article/wp7_jump_start

*Education http://create.msdn.com/en-US/education/

Page 21: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*My latest game

MonsterUp

Page 22: YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

*My latest game

MonsterUp