Audio in CocosSharp

PDF for offline use

Let us know how you feel about this

Translation Quality


0/250

How to play sound and music in CocosSharp

Recipe

Audio can be played using the CCAudioEngine class. Background music is streamed from device, and is typically represented by a compressed file format. Sound effects are played from uncompressed files.

The following code shows how to play background music:

CCAudioEngine.SharedEngine.PlayBackgroundMusic (
    filename:"FruityFalls",
    loop:false);

The following code shows how to play a sound effect:

CCAudioEngine.SharedEngine.PlayEffect (filename:"Electricity");

CocosSharp supports the MonoGame content pipeline types (.xnb files) for music and sound effects. For information on using the content pipeline, see the CocosSharp Content Pipeline Guide.

For a full example on playing audio, see the CCAudioEngine sample.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.