1 / 21

A Simple Game with Particles and Sound

A Simple Game with Particles and Sound. Cameron Haider. Check every cannonball within the update window. And add a particle system if desired. if ( t.Equals (new Vector3(1.0f ))) { //if projectile is traveling MakeSmoke (cannonball[ i ].position, false ); }.

mimi
Télécharger la présentation

A Simple Game with Particles and Sound

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A Simple Game with Particles and Sound Cameron Haider

  2. Check every cannonball within the update window. And add a particle system if desired.

  3. if (t.Equals(new Vector3(1.0f))){ //if projectile is traveling MakeSmoke(cannonball[i].position, false); }

  4. if (cannonball[i].UpdateProjectile(gameTime) .Equals(new Vector3(0.0f)) //hits the ground for (int x = 0; x < 25; x++) //Make a lot of Smoke and fire MakeSmoke(cannonball[i].position, true);

  5. ParticleSystem(intnParticles, Vector2 particleSize, floatlifespan, Vector3 wind, float FadeInTime) fire = new ParticleSystem(400, new Vector2(400), 1, Vector3.Zero, 0.5f); smoke = new ParticleSystem(800, new Vector2(400), 5, new Vector3(5f, 0f, 0f), 5f); Smoke creation has a short delay and lingers longer than fire.

  6. public void MakeSmoke(Vector3 parPo, Boolean flame) { Vector3 offset = new Vector3(MathHelper.ToRadians(10.0f)); Vector3 randAngle = Vector3.Up + randVec3(-offset, offset); float randSpeed = (float)r.NextDouble() * 100 + 300; if (flame) { ps.AddParticle(parPo, randAngle, randSpeed); ps.Update(); } smoke.AddParticle(parPo + new Vector3(0, 10, 0), randAngle, randSpeed); smoke.Update(); } Making Smoke

  7. Two Choices for Sound • Default Sound API (SoundEffects Class) • XACT (Cross-platform Audio Creation Tool)

  8. Default Sound API • SoundEffect and SoundEffectInstance classes. • Capable of streaming audio, must use wav format. • Slower runtime than using the content pipeline. • May build audio in the content pipeline, source does not matter. • Mp3, wma, wav and others may be loaded through the ContentManager, thus converting them into the XNB (XNA Framework Content Pipeline Binary file) format. • Creation is a simple as: • SoundEffect fire = Content.Load<SoundEffect>("Sounds\\fire"); • Use of the sound effect is a simple as: • fire.Play();

  9. XACT (Cross-platform Audio Creation Tool) • May only import uncompressed audio (pcmwav and aiff) • Allows separation of Audio engineer’s and programmer’s responsibilities.

  10. XACT - Example • Launch XACT and create a new xact project inside of the sound content directory of your visual studio project.

  11. Create a new Wave Bank and Sound Bank • Right Click both Wave Bank and Sound Bank, create a new file for each. • Both of the new banks should open in separate windows, click in the middle of the Wave Bank window and insert your wav files. • Drag the new files from the wave bank into the bottom half of the Sound Bank. This will populate the top half of the Sound bank at the same time.

  12. Waves, Sounds and Cues • Waves are uncompressed audio data. • Sounds are collections of instructions to regulate how the wave files are played. • Cues are the objects called to play specified Sounds. With XACT you should only be referring to Cue objects, to play and control your audio. You can either save the Cue objects in memory or retrieve them from your xact project for every event. An example modifying a Cue to simulate 3D positioning: Cue.Apply3D(AudioListner listener, AudioEmitter emitter); //AudioListener and AdioEmitter simply contain: Speed, //Magnitude and Direction of both the noise’s origin and our listener

  13. Sounds – Control Additional Effects • Categories: Group Sounds together • RPC: Run-Time parameter controls, aka Sliders • DSP: digital signal processing effects, such as reverb • Compression

  14. Sounds - RPC An example of this is when Audio waves and pitches for an engine are adjusted as the gear and RPMs change. Run-Time parameter controls are known as sliders because some attribute/s of the sound is altered based on a graph and some variable.

  15. Sounds - DSP Digital Signal Processing effects, such as reverb

  16. Sounds - Compression Allows sound quality to be set.

  17. Global and Cue, Variables Variables are either Global or Cue based. They can be applied to RPCs.

  18. Variable Overview

  19. Looping Sound in XACT This is done from inside the XACT application. Select the file from the Sound bank and the file details will display on the lower left hand side. In the Looping section of the detail window, either input a number for the loop count or mark the infinite option.

  20. Playing SoundWeapon Fire privatevoidFireBullet(GameTimegameTime) { *** //Create Projectile *** soundBank.PlayCue("fire"); } • Send the soundBank’sPlayCue() method, the Cue name of the desired sound.

More Related