Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Playing a random sound in my program  (Read 2281 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Playing a random sound in my program
« on: May 10, 2019, 11:33:52 pm »
I'm creating a game in which a random sound should play when reaching a particular score. Sadly, I'm a beginner and I have no idea how to do this, I'm only able to get a random number with of the Randomizer function but it's not helpful in this case anyways. Could anyone help me with this?


  • Hero Member
  • *****
  • Posts: 3100
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Playing a random sound in my program
« Reply #1 on: May 11, 2019, 01:14:37 am »
You could have a vector of sf::Sounds and then pick a random number between 0 and the size of vector - 1, which would be the vector's index and therefore which sound that would be used.

Which "Randomizer function"?
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

Hapaxia Links