Cocos2d x 音訊功能學習筆記

2021-07-04 03:22:04 字數 4704 閱讀 4674

******audioengine api的使用非常簡單。

1

2

3

4

5

auto audio = ******audioengine::getinstance();

// set the background music and continuously play it.

audio->playbackgroundmusic("mymusic.***",true);

// set the background music and play it just once.

audio->playbackgroundmusic("mymusic.***",false);

12

3

4

auto audio = ******audioengine::getinstance();

// play a sound effect, just once.

audio->playeffect("myeffect.***",false, 1.0f, 1.0f, 1.0f);

暫停1

2

3

4

5

6

7

8

9

10

auto audio = ******audioengine::getinstance();

// pause background music.

audio->pausebackgroundmusic();

// pause a sound effect.

audio->pauseeffect();

// pause all sound effects.

audio->pausealleffects();

停止1

2

3

4

5

6

7

8

9

10

auto audio = ******audioengine::getinstance();

// stop background music.

audio->stopbackgroundmusic();

// stop a sound effect.

audio->stopeffect();

// stops all running sound effects.

audio->stopalleffects();

resume 恢復

1

2

3

4

5

6

7

8

9

10

auto audio = ******audioengine::getinstance();

// resume background music.

audio->resumebackgroundmusic();

// resume a sound effect.

audio->resumeeffect();

// resume all sound effects.

audio->resumealleffects();

setup 設定

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

// it's be invoked too

void

director::getinstance()->stopanimation();

// if you use ******audioengine, it must be pause

// ******audioengine::getinstance()->pausebackgroundmusic();

}

void

director::getinstance()->startanimation();

// if you use ******audioengine, it must resume here

// ******audioengine::getinstance()->resumebackgroundmusic();

}

如果你要用******audioengine實現背景**和音效,那麼就需要注意別忘了去掉**中有用**的注釋。

預載入音效

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

auto audio = ******audioengine::getinstance();

// pre-loading background music and effects. you could pre-load

// when you want to use them.

audio->preloadbackgroundmusic("mymusic1.***");

audio->preloadbackgroundmusic("mymusic2.***");

audio->preloadeffect("myeffect1.***");

audio->preloadeffect("myeffect2.***");

// unload a sound from cache. if you are finished with a sound and

// you wont use it anymore in your game. unload it to free up

// resources.

audio->unloadeffect("myeffect1.***");

音量你可以通過程式的控制來增大減小音量。

1

2

3

4

auto audio = ******audioengine::getinstance();

// setting the volume specifying value as a float

audio->seteffectsvolume(5.0f);

cocos2dx 使用音訊需要注意

後面問了一些人,他們說本文章提到的問題應該不會出現,所以可能是我的庫類沒弄好.汗 今天我用了cocos2dx裡比較簡單的音訊類 audioengine sharedengine playbackgroundmusic music background music.然後執行程式,成功!但是,關閉程式的...

Cocos2d x學習筆記1

1.建立新的cocos2d x 3.0 專案 在命令列中輸入 cocos new helloworld 專案名稱 p com.ss.pku 包名字 l cpp 專案型別 d d cocos workspace 專案存放路徑 2.資料夾分析 resource 資料夾 存放資源檔案 include和so...

Cocos2d x學習筆記(7)

1 動作基本概念 ccactiong是動作類的基類,動作作用於ccnode,因此,任何乙個動作都需要ccnode物件來執行。ccaction作為乙個基類,其實質是乙個介面 抽象類 由它派生的實現類才是實際使用的動作。ccaction的絕大多數實現類都派生自ccfinitetimeaction,這個類...