Learn WP7 XNA Game Development (five Sound)

Source: Internet
Author: User
Tags add resource static class

Sound is a very important part of the game, and for sound it is divided into audio and music, and in this respect XNA also provides a convenient way to manage and play.

A Audio: Generally used to play some very short WAV format audio, such as clicks and other sound effects.

The SoundEffect in the Microsoft.Xna.Framework.Audio namespace includes the processing APIs for Audio, such as play, Stop, pause, and so on, which can also be looped.

SoundEffect SE =. Game.Content.Load ("Hit");

Se. Greateinstance (). Play ();

Se. Greateinstance (). Stop ();

Se. Greateinstance (). Pause ()/Pause

Se. Greateinstance (). Resume ()/Continue

Se. Greateinstance (). islooped = true;//Loop playback

If a lot of sound, you need to manage, you can load the time to add all the resources to a list of management, when needed to be transferred out.

Dictionary audiolist//can use Dictionary to save all sound resources, and its advantage is that resources can be indexed by name.

SoundEffect se = Game.Content.Load ("Sound Resource Name");/load Sound resources

Audiolist.add (Key, SE. CreateInstance ());//Storage resources

audiolist["Sound resource Name"]. Play ()//Get resources and playback

audiolist["Sound resource Name"]. state = = soundstate.playing//Get sound status

Two Music: Music that can be played in MP3 and other formats. Can be used to play background music.

The song in the Microsoft.Xna.Framework.Media namespace includes the processing API for song, such as the name of the music, album, Singer, Time, and so on. But this class can not be used for music play, Stop, Pause, repeat and other operations, you need to mediaplayer this static class to achieve.

Song = Content.load ("Kalimba");

Mediaplayer.isrepeating = true;

Mediaplayer.play (Song);



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.