Corrected audio bugs and improved examples

This commit is contained in:
raysan5 2016-09-15 11:53:16 +02:00
parent 9923fe51a7
commit 79c8eb543e
3 changed files with 93 additions and 60 deletions

View file

@ -62,6 +62,7 @@ int main()
PlayMusicStream(xm);
float timePlayed = 0.0f;
bool pause = false;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -71,7 +72,29 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
for (int i = MAX_CIRCLES - 1; i >= 0; i--)
UpdateMusicStream(xm); // Update music buffer with new stream data
// Restart music playing (stop and play)
if (IsKeyPressed(KEY_SPACE))
{
StopMusicStream(xm);
PlayMusicStream(xm);
}
// Pause/Resume music playing
if (IsKeyPressed(KEY_P))
{
pause = !pause;
if (pause) PauseMusicStream(xm);
else ResumeMusicStream(xm);
}
// Get timePlayed scaled to bar dimensions
timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2;
// Color circles animation
for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--)
{
circles[i].alpha += circles[i].speed;
circles[i].radius += circles[i].speed*10.0f;
@ -88,11 +111,6 @@ int main()
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
}
}
// Get timePlayed scaled to bar dimensions
timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2;
UpdateMusicStream(xm); // Update music buffer with new stream data
//----------------------------------------------------------------------------------
// Draw

View file

@ -28,9 +28,8 @@ int main()
PlayMusicStream(music);
int framesCounter = 0;
float timePlayed = 0.0f;
//float volume = 1.0;
bool pause = false;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@ -40,28 +39,26 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
framesCounter++;
// Testing music fading from one file to another
/*
if (framesCounter > 600) // Wait for 10 seconds (600 frames)
{
volume -= 0.01; // Decrement music volume level
// When music volume level equal or lower than 0,
// restore volume level and init another music file
if (volume <= 0)
{
volume = 1.0;
framesCounter = 0;
}
SetMusicVolume(volume);
}
*/
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4; // We scale by 4 to fit 400 pixels
UpdateMusicStream(music); // Update music buffer with new stream data
// Restart music playing (stop and play)
if (IsKeyPressed(KEY_SPACE))
{
StopMusicStream(music);
PlayMusicStream(music);
}
// Pause/Resume music playing
if (IsKeyPressed(KEY_P))
{
pause = !pause;
if (pause) PauseMusicStream(music);
else ResumeMusicStream(music);
}
// Get timePlayed scaled to bar dimensions (400 pixels)
timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4;
//----------------------------------------------------------------------------------
// Draw
@ -70,10 +67,14 @@ int main()
ClearBackground(RAYWHITE);
DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY);
DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY);
DrawRectangle(200, 250, 400, 12, LIGHTGRAY);
DrawRectangle(200, 250, (int)timePlayed, 12, MAROON);
DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
DrawRectangle(200, 200, (int)timePlayed, 12, MAROON);
DrawRectangleLines(200, 200, 400, 12, GRAY);
DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY);
DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY);
EndDrawing();
//----------------------------------------------------------------------------------