Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

66 wiersze
2.5 KiB

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