安卓開發(fā)游戲音效代碼實例
來源:易賢網(wǎng) 閱讀:1080 次 日期:2014-08-21 15:57:32
溫馨提示:易賢網(wǎng)小編為您整理了“安卓開發(fā)游戲音效代碼實例”,方便廣大網(wǎng)友查閱!

//音效的音量

int streamVolume;

//定義SoundPool 對象 private SoundPool soundPool;

//定義HASH表 private HashMap<Integer, Integer> soundPoolMap;

/*************************************************************** * Function: initSounds();

* Parameters: null

* Returns: None.

* Description: 初始化聲音系統(tǒng)

* Notes: none.

***************************************************************/

public void initSounds() { //初始化soundPool 對象,第一個參數(shù)是允許有多少個聲音流同時播放,第2個參數(shù)是聲音類型,第三個參數(shù)是聲音的品質(zhì) soundPool = new SoundPool(100, AudioManager.STREAM_MUSIC, 100);

//初始化HASH表 soundPoolMap = new HashMap<Integer, Integer>();

//獲得聲音設(shè)備和設(shè)備音量 AudioManager mgr = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);

streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);

}

/*************************************************************** * Function: loadSfx();

* Parameters: null

* Returns: None.

* Description: 加載音效資源

* Notes: none.

***************************************************************/

public void loadSfx(int raw, int ID) { //把資源中的音效加載到指定的ID(播放的時候就對應(yīng)到這個ID播放就行了) soundPoolMap.put(ID, soundPool.load(context, raw, ID));

}

/*************************************************************** * Function: play();

* Parameters: sound:要播放的音效的ID, loop:循環(huán)次數(shù)

* Returns: None.

* Description: 播放聲音

* Notes: none.

***************************************************************/

public void play(int sound, int uLoop) { soundPool.play(soundPoolMap.get(sound), streamVolume, streamVolume, 1, uLoop, 1f); }

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:安卓開發(fā)游戲音效代碼實例

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)