SFML: sound and music

This article is part of a tutorial dedicated to SFML. The reader may consult the other parts of the tutorial by following this link : SFML tutorial.

This example shows how to play music and sound.

/*!
 * \file    main.cpp
 * \brief   Music and sound examples (http://www.lucidarme.me/?p=6127)
 * \author  Philippe Lucidarme
 * \version 1.0
 * \date    12/20/2016
 */

#include 
#include 


// Wait for ms milliseconds
void delay_ms(int ms)
{
    sf::Clock Timer;
    while (Timer.getElapsedTime().asMilliseconds()5;vol--)
    {
        music.setVolume(vol);
        delay_ms(50);
    }

    // Stop music
    std::cout << "Stop music" << std::endl;
    music.stop();
    return 0;
}

Download from Git

Files, sharders and source codes can be downloaded for GitLab : https://gitlab.com/philippe.lucidarme/sfml_tutorial/tree/master/part_009

<- Back to SFML tutorial main menu

Leave a Reply

Your email address will not be published. Required fields are marked *