22
YMTIS Workshop Geneva Introduction to XNA Marios Karagiannis

* 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 &

  • View
    214

  • Download
    1

Embed Size (px)

Citation preview

YMTIS WorkshopGeneva

Introduction to XNAMarios 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

*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)

*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

*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

* XNA for Windows Phone 7

*Game loop vs event driven programming

*Games play even when you don’t

Update Draw

*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

*Game timing

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

*Variable Time StepBe careful to use ElapsedGameTime (more

traditional way to develop games)

Update

Draw

*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

*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/

*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)

*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

*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

*Let’s see how easy it is

When you start a new Windows Phone 7 XNA Game everything is setup for you:

Your Game class

A spriteBatch object to draw sprites

Your Graphics Devide Manager object

Your Content root

Your Initialize function

Your LoadContent function

Your UnloadContent function

Your Update function

Your Draw function Update Draw

Start

Initialize

LoadContent

UnloadContent

Finish

*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)); }

}

*A few examples

*How to use the accelerometer

*Use a ReadingChanged event

*Read 3 axis data

*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;

}

*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;

}

*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.

} }

*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/

*My latest game

MonsterUp

*My latest game

MonsterUp