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.

58 lines
2.3 KiB

  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.6 (www.raylib.com)
  8. -- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  9. --
  10. -- Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
  11. --
  12. -------------------------------------------------------------------------------------------
  13. -- Initialization
  14. -------------------------------------------------------------------------------------------
  15. local screenWidth = 800
  16. local screenHeight = 450
  17. InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing")
  18. InitAudioDevice() -- Initialize audio device
  19. local fxWav = LoadSound("resources/audio/weird.wav") -- Load WAV audio file
  20. local fxOgg = LoadSound("resources/audio/tanatana.ogg") -- Load OGG audio file
  21. SetTargetFPS(60)
  22. -------------------------------------------------------------------------------------------
  23. -- Main game loop
  24. while not WindowShouldClose() do -- Detect window close button or ESC key
  25. -- Update
  26. ---------------------------------------------------------------------------------------
  27. if (IsKeyPressed(KEY.SPACE)) then PlaySound(fxWav) end -- Play WAV sound
  28. if (IsKeyPressed(KEY.ENTER)) then PlaySound(fxOgg) end -- Play OGG sound
  29. ---------------------------------------------------------------------------------------
  30. -- Draw
  31. ---------------------------------------------------------------------------------------
  32. BeginDrawing()
  33. ClearBackground(RAYWHITE)
  34. DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY)
  35. DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY)
  36. EndDrawing()
  37. ---------------------------------------------------------------------------------------
  38. end
  39. -- De-Initialization
  40. -------------------------------------------------------------------------------------------
  41. UnloadSound(fxWav) -- Unload sound data
  42. UnloadSound(fxOgg) -- Unload sound data
  43. CloseAudioDevice() -- Close audio device
  44. CloseWindow() -- Close window and OpenGL context
  45. -------------------------------------------------------------------------------------------