Presentation is loading. Please wait.

Presentation is loading. Please wait.

XNA Sound Effects. float volume, pitch, pan; SoundEffect boing1; SoundEffect boing2; boing1 = Content.Load ("boing1"); boing2 = Content.Load ("boing2");

Similar presentations


Presentation on theme: "XNA Sound Effects. float volume, pitch, pan; SoundEffect boing1; SoundEffect boing2; boing1 = Content.Load ("boing1"); boing2 = Content.Load ("boing2");"— Presentation transcript:

1 XNA Sound Effects

2 float volume, pitch, pan; SoundEffect boing1; SoundEffect boing2; boing1 = Content.Load ("boing1"); boing2 = Content.Load ("boing2"); pitch = (float)((double)(spritescale * 2.0-2.0)); pan = -(float)(((((double)maxX-(double)facePosition.X)/maxX)*2.0)-1.0); boing2.Play(volume,pitch,pan); Example Sound Effects in faceBall4.zip Sound effects variables declared as global Sound effects loaded in Content.Load( ) method (see Lecture 2 for how to associate.wav files with project (same procedure as used to associate bitmaps with project). Range of valid values for pitch are from -1.0 (down one octave) to +1.0 (up an octave). Normal pitch is at value 0.0 Value of pan sets relative volume in left (-1.0) and right(1.0) speakers. Center value 0.0. Example

3 protected override void Update(GameTime gameTime) { int i, j; pitch = (float)((double)(spritescale/2.0 -1.0)); pan = -(float)(((((double)maxX - (double)facePosition.X) / maxX) * 2.0) - 1.0); spriterot -= (float)0.05; if (spriterot > 6.28) spriterot = (float)0.0; if (spriterot < 0.0) spriterot = (float)6.28; spritescale += delscale; if ((spritescale > (float)2.0) || (spritescale < (float)0.5)) delscale *= (float)-1.0; if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); Example Integrating Sound Effects into the Update( ) Method

4 facePosition.X += faceVx; if (facePosition.X > maxX - blit.Width / 2) { faceVx *= -1; boing1.Play(1, pitch, pan); } if (facePosition.X < minX + blit.Width / 2) { faceVx *= -1; boing1.Play(1,pitch, pan); } facePosition.Y += faceVy; if (facePosition.Y > maxY - blit.Height / 2) { faceVy *= -1; boing2.Play(1, pitch, pan); } if (facePosition.Y < minY + blit.Height / 2) { faceVy *= -1; boing2.Play(1,pitch,pan); } if (rnd.Next(1000)>990) { i = rnd.Next(4); j = rnd.Next(2); blit.X = i * 90; blit.Y = j * 85; } base.Update(gameTime); }

5 SoundEffect wind; SoundEffectInstance thewind; wind = Content.Load ("wind"); thewind = wind.CreateInstance(); thewind.IsLooped = true; thewind.Play(); thewind.Pause(); thewind.Resume(); thewind.Stop(); Looping a Sound Any SoundEffect can be looped or played repeatedly by creating an instance of the effect, settng its IsLooped boolean property to true and then playing the instance. Note that since the sound is being looped, thewind.Play( ) has to be called only once. In addition the looping sound can be paused, resumed, and stopped using the calls to methods of the same name. declare variables globally so that they are accessible anywhere in the project code instance is created in LoadContent( ) after associated soundeffect is loaded. state of instance can be changed in any methods in the project


Download ppt "XNA Sound Effects. float volume, pitch, pan; SoundEffect boing1; SoundEffect boing2; boing1 = Content.Load ("boing1"); boing2 = Content.Load ("boing2");"

Similar presentations


Ads by Google