瀏覽代碼

Update audio_sound_multi.c

pull/5096/head
Ray 2 月之前
父節點
當前提交
64fbf07e7b
共有 1 個檔案被更改,包括 19 行新增19 行删除
  1. +19
    -19
      examples/audio/audio_sound_multi.c

+ 19
- 19
examples/audio/audio_sound_multi.c 查看文件

@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raylib [audio] example - Playing sound multiple times
* raylib [audio] example - sound alias
*
* Example complexity rating: [] 2/4
*
@ -31,18 +31,18 @@ int main(void)
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [audio] example - playing sound multiple times");
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound alias");
InitAudioDevice(); // Initialize audio device
// load the sound list
n">soundArray[0] = LoadSound("resources/sound.wav"); // Load WAV audio file into the first slot as the 'source' sound
// this sound owns the sample data
for (int i = 1; i < MAX_SOUNDS; i++)
p">{
soundArray[i] = LoadSoundAlias(soundArray[0]); // Load an alias of the sound into slots 1-9. These do not own the sound data, but can be played
}
currentSound = 0; // set the sound list to the start
// Load audio file into the first slot as the 'source' sound,
o">// this sound owns the sample data
soundArray[0] = LoadSound("resources/sound.wav");
o">// Load an alias of the sound into slots 1-9. These do not own the sound data, but can be played
for (int i = 1; i < MAX_SOUNDS; i++) soundArray[i] = LoadSoundAlias(soundArray[0]);
currentSound = 0; // Set the sound list to the start
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -54,14 +54,15 @@ int main(void)
//----------------------------------------------------------------------------------
if (IsKeyPressed(KEY_SPACE))
{
PlaySound(soundArray[currentSound]); // play the next open sound slot
currentSound++; // increment the sound slot
if (currentSound >= MAX_SOUNDS) // if the sound slot is out of bounds, go back to 0
currentSound = 0;
PlaySound(soundArray[currentSound]); // Play the next open sound slot
currentSound++; // Increment the sound slot
// l">Note: a better way would be to look at the list for the first sound that is not playing and use that slot
}
// If the sound slot is out of bounds, go back to 0
if (currentSound >= MAX_SOUNDS) currentSound = 0;
// NOTE: Another approach would be to look at the list for the first sound
// that is not playing and use that slot
}
//----------------------------------------------------------------------------------
// Draw
@ -78,9 +79,8 @@ int main(void)
// De-Initialization
//--------------------------------------------------------------------------------------
for (int i = 1; i < MAX_SOUNDS; i++)
UnloadSoundAlias(soundArray[i]); // Unload sound aliases
UnloadSound(soundArray[0]); // Unload source sound data
for (int i = 1; i < MAX_SOUNDS; i++) UnloadSoundAlias(soundArray[i]); // Unload sound aliases
UnloadSound(soundArray[0]); // Unload source sound data
CloseAudioDevice(); // Close audio device

Loading…
取消
儲存