outline 7.1collision detection in 2d & 3d 7.2types of collision detection

15
1 Aaron Yuen Outline 7.1 Collision Detection in 2D & 3D 7.2 Types of Collision Detection 7.3 Implementing Collision Detection in a Project 7.4 Problem Solving 7.5 Audio with 2D game and 3D game with XACT 7.6 Implementing Sounds and Effects in the Game 7.7 Playing Opening Movie in XNA MTA-4201 Game Programming Chapter 7 : Collision Detection & Multimedia Elements

Upload: alfonso-baldwin

Post on 02-Jan-2016

46 views

Category:

Documents


3 download

DESCRIPTION

MTA-4201 Game Programming Chapter 7 : Collision Detection & Multimedia Elements. Outline 7.1Collision Detection in 2D & 3D 7.2Types of Collision Detection 7.3Implementing Collision Detection in a Project 7.4Problem Solving 7.5Audio with 2D game and 3D game with XACT - PowerPoint PPT Presentation

TRANSCRIPT

1

Aaron Yuen

Outline7.1 Collision Detection in 2D & 3D7.2 Types of Collision Detection 7.3 Implementing Collision Detection in a Project7.4 Problem Solving7.5 Audio with 2D game and 3D game with XACT7.6 Implementing Sounds and Effects in the Game7.7 Playing Opening Movie in XNA

MTA-4201 Game ProgrammingChapter 7 : Collision Detection & Multimedia Elements

2

Aaron Yuen

7.1 Collision Detection in 2D & 3D

• Contains and Intersects Methods• Bounding volume classes have methods to support two

types of collision tests: intersection tests and containment tests. The intersects methods check whether the two objects being tested overlap in any way. As soon as the test finds that the objects do intersect, it returns without trying to determine the degree of the intersection. The contains methods determine whether the objects simply intersect or whether one of the objects is completely contained by the other. Since the intersects methods need only determine whether an intersection occurred, they tend to be faster than the contains methods. Use the contains methods only when the degree of intersection is relevant.

3

Aaron Yuen

(1) Rectangle Detection Contains & Intersects method

7.2 Types of Collision Detection

4

Aaron Yuen

(2) Per-Pixel Collision (Pixel Perfect)

Per-pixel collision requires examining individual pixels of a given texture. If there is overlapping pixel, collision happens. This is called per-pixel collision.

7.2 Types of Collision Detection

5

Aaron Yuen

(2) Per-Pixel Collision (Pixel Perfect)

Rectangle Collision Detection has exclusive use of rectangles resulted in imprecise behavior for non-rectangular objects.

In order to achieve the desired behavior, the code must examine every overlapping pixel to determine if there is a collision. This is called per-pixel collision.

7.2 Types of Collision Detection

6

Aaron Yuen

7.3 Implementing Per-Pixel Collision Detection

Step 1 : Get Texture Data

Per-pixel collision requires examining individual pixels of a given texture. To access the individual pixels, you must call Texture2D.GetData. This method copies the pixels into an array of pixel data of type Color.

Step 2 : Write Per-Pixel Collision Method

A method should be written to perform the per-pixel collision test.

Step 3 : Invoke the Per-pixel Collision Test

The method should be called in the Update( ) method.

If you needs to implement Per-Pixel Collision Detection in your game project, follow the detailed instructions in the following link :

PerPixelCollision/PerPixelCollision.htm

7

Aaron Yuen

7.3 Implementing Per-Pixel Collision Detection

8

Aaron Yuen

7.4 Problem Solving

How do you make the triangles randomly drops from the top of the screen?

9

Aaron Yuen

7.5 Audio with 2D Game -- Microsoft Cross-Platform

Audio Creation Tool (XACT)• Music sets the atmosphere for our games and

sound effects adds to the realism of our games.

• In XNA, we need to use Microsoft Cross-Platform Audio Creation Tool (XACT), which Microsoft provides for us.

• The tool is in the programs menu:

10

Aaron Yuen

Wave Banks – holds raw audio data.

Sound Banks – contains instructions on how to play audio data.

11

Aaron Yuen

Wave Bank To insert wave into the Wave Bank, the steps are :

Step 1 :Open a new Wave Bank, right click on the Wave Bank window;

Step 2 : Select the wave files to be added into the game.

12

Aaron Yuen

Sound BanksThen you need to import the raw data from Wave Bank to

Sound Bank to allow the XNA to use it.Step 1 :

Select the files from the Wave bank window;

Step 2 : Drag the files to the bottom of the Sound Bank. It is done.

13

Aaron Yuen

7.6 Ready to Play Sounds

Open a new XNA project with C#

Step 1 :

Import the XACT project to the XNA project.

The sounds are then added to the project.

14

Aaron Yuen

7.6 Ready to Play Sound with CodingIn Game1.cs :

public class Game1 : Microsoft.Xna.Framework.Game

{

…….

AudioEngine audioEngine;

SoundBank soundBank;

WaveBank waveBank;

…….

}

Protected override void LoadContent()

{

…………

// Inilization of the Wave files with the AudioEngine

audioEngine = new AudioEngine(“Content\\Audio\\TutorialAudio.xgs”);

waveBank = new WaveBank(audioEngine, “Content\\Audio\\Wave Bank.xwb”);

soundBank = new SoundBank(audioEngine, “Content\\Audio\\Sound Bank.xsb”);

…………..

}

protected override void Update(GameTime gameTime)

{

………….

audioEngine.Update();

…………..

}

To play a wave, type this code :

soundBank.PlayCue(“missilelaunch”);

15

Aaron Yuen

Video Support in XNA Game Studio 3.1:

http://klucher.com/blog/video-support-in-xna-game-studio-3-1/

Method with 3.0 which does not support in XBOX360:

http://www.codeplex.com/XNADSPlayer/Release/ProjectReleases.aspx?ReleaseId=11066

7.7 Playing Opening Movie in XNA