You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 line
2.5 KiB

11 年之前
11 年之前
11 年之前
11 年之前
11 年之前
11 年之前
11 年之前
11 年之前
11 年之前
11 年之前
11 年之前
11 年之前
  1. /*******************************************************************************************
  2. *
  3. * raylib [audio] example - Sound loading and playing
  4. *
  5. * This example has been created using raylib 1.0 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Copyright (c) 2014 Ramon Santamaria (@raysan5)
  9. *
  10. ********************************************************************************************/
  11. #include "raylib.h"
  12. int main(void)
  13. {
  14. // Initialization
  15. //--------------------------------------------------------------------------------------
  16. const int screenWidth = 800;
  17. const int screenHeight = 450;
  18. InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
  19. InitAudioDevice(); // Initialize audio device
  20. Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
  21. Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file
  22. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  23. //--------------------------------------------------------------------------------------
  24. // Main game loop
  25. while (!WindowShouldClose()) // Detect window close button or ESC key
  26. {
  27. // Update
  28. //----------------------------------------------------------------------------------
  29. if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
  30. if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
  31. //----------------------------------------------------------------------------------
  32. // Draw
  33. //----------------------------------------------------------------------------------
  34. BeginDrawing();
  35. ClearBackground(RAYWHITE);
  36. DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
  37. DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
  38. EndDrawing();
  39. //----------------------------------------------------------------------------------
  40. }
  41. // De-Initialization
  42. //--------------------------------------------------------------------------------------
  43. UnloadSound(fxWav); // Unload sound data
  44. UnloadSound(fxOgg); // Unload sound data
  45. CloseAudioDevice(); // Close audio device
  46. CloseWindow(); // Close window and OpenGL context
  47. //--------------------------------------------------------------------------------------
  48. return 0;
  49. }