Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

68 lignes
2.8 KiB

il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
  1. /*******************************************************************************************
  2. *
  3. * raylib [audio] example - Sound loading and playing
  4. *
  5. * Example originally created with raylib 1.1, last time updated with raylib 3.5
  6. *
  7. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software
  9. *
  10. * Copyright (c) 2014-2024 Ramon Santamaria (@raysan5)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. //------------------------------------------------------------------------------------
  15. // Program main entry point
  16. //------------------------------------------------------------------------------------
  17. int main(void)
  18. {
  19. // Initialization
  20. //--------------------------------------------------------------------------------------
  21. const int screenWidth = 800;
  22. const int screenHeight = 450;
  23. InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing");
  24. InitAudioDevice(); // Initialize audio device
  25. Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file
  26. Sound fxOgg = LoadSound("resources/target.ogg"); // Load OGG audio file
  27. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  28. //--------------------------------------------------------------------------------------
  29. // Main game loop
  30. while (!WindowShouldClose()) // Detect window close button or ESC key
  31. {
  32. // Update
  33. //----------------------------------------------------------------------------------
  34. if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound
  35. if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound
  36. //----------------------------------------------------------------------------------
  37. // Draw
  38. //----------------------------------------------------------------------------------
  39. BeginDrawing();
  40. ClearBackground(RAYWHITE);
  41. DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY);
  42. DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY);
  43. EndDrawing();
  44. //----------------------------------------------------------------------------------
  45. }
  46. // De-Initialization
  47. //--------------------------------------------------------------------------------------
  48. UnloadSound(fxWav); // Unload sound data
  49. UnloadSound(fxOgg); // Unload sound data
  50. CloseAudioDevice(); // Close audio device
  51. CloseWindow(); // Close window and OpenGL context
  52. //--------------------------------------------------------------------------------------
  53. return 0;
  54. }