Correction bug de chargement musiques
This commit is contained in:
parent
7e74ba7393
commit
fd20287966
|
@ -90,11 +90,6 @@ public:
|
|||
* Modifie le temps total du niveau
|
||||
*/
|
||||
virtual void setTotalTime(int set_total_time);
|
||||
|
||||
/**
|
||||
* Modifie la musique du niveau
|
||||
*/
|
||||
virtual void setMusic(std::string set_music);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,8 +27,10 @@ private:
|
|||
boost::filesystem::path levels_path;
|
||||
|
||||
boost::filesystem::path musics_path;
|
||||
float music_volume;
|
||||
sf::Music music;
|
||||
float music_volume;
|
||||
bool playing_state;
|
||||
std::string current_music;
|
||||
|
||||
public:
|
||||
ResourceManager();
|
||||
|
|
|
@ -29,11 +29,7 @@ inline sf::Vector2f roundVectorToGrid(sf::Vector2f input) {
|
|||
Editor::Editor(Manager& manager) : Level(manager),
|
||||
drag_control_point(nullptr), drag_mode(Editor::DragMode::NONE),
|
||||
widget_timer(manager, true, std::bind(&Editor::setTotalTime, this, std::placeholders::_1)),
|
||||
widget_toolbar(manager) {
|
||||
|
||||
getResourceManager().playMusic("editor.ogg");
|
||||
getWindow().setFramerateLimit(Manager::FPS);
|
||||
}
|
||||
widget_toolbar(manager) {}
|
||||
|
||||
Editor::~Editor() {}
|
||||
|
||||
|
@ -241,6 +237,8 @@ void Editor::processEvent(const sf::Event& event) {
|
|||
void Editor::frame() {
|
||||
// titre de la fenêtre
|
||||
getManager().setTitle(sf::String(L"Édition de ") + getName());
|
||||
getResourceManager().playMusic("editor.ogg");
|
||||
getWindow().setFramerateLimit(Manager::FPS);
|
||||
|
||||
// dessin de la frame
|
||||
draw();
|
||||
|
|
23
src/game.cpp
23
src/game.cpp
|
@ -9,8 +9,6 @@ Game::Game(Manager& manager) : Level(manager),
|
|||
next_frame_time(manager.getCurrentTime()) {
|
||||
mode = Game::Mode::NORMAL;
|
||||
death_cause = Game::DeathCause::NONE;
|
||||
|
||||
getWindow().setFramerateLimit(0);
|
||||
}
|
||||
|
||||
Game::~Game() {}
|
||||
|
@ -39,6 +37,15 @@ void Game::processEvent(const sf::Event& event) {
|
|||
void Game::frame() {
|
||||
// titre de la fenêtre
|
||||
getManager().setTitle(getName());
|
||||
getWindow().setFramerateLimit(0);
|
||||
|
||||
// si musique il y a, on la joue
|
||||
if (getMusic() != "") {
|
||||
getResourceManager().playMusic(getMusic());
|
||||
} else {
|
||||
getResourceManager().stopMusic();
|
||||
}
|
||||
|
||||
sf::Time current_time = getManager().getCurrentTime();
|
||||
|
||||
if (current_time >= next_frame_time) {
|
||||
|
@ -257,15 +264,3 @@ void Game::setTotalTime(int set_total_time) {
|
|||
Level::setTotalTime(set_total_time);
|
||||
time_left = getTotalTime();
|
||||
}
|
||||
|
||||
void Game::setMusic(std::string set_music) {
|
||||
Level::setMusic(set_music);
|
||||
|
||||
// lorsqu'on change la musique, on commence à la jouer
|
||||
// si toutefois il y en a une
|
||||
if (getMusic() != "") {
|
||||
getResourceManager().playMusic(getMusic());
|
||||
} else {
|
||||
getResourceManager().stopMusic();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,6 @@ const float MAX_WIDTH_PROPORTION = 1.f / 3.f;
|
|||
Menu::Menu(Manager& manager) : State(manager) {
|
||||
background.setTexture(getResourceManager().getTexture("bg_menu.tga"));
|
||||
loadMainMenu();
|
||||
|
||||
getResourceManager().playMusic("menu.ogg");
|
||||
getWindow().setFramerateLimit(Manager::FPS);
|
||||
}
|
||||
|
||||
Menu::~Menu() {}
|
||||
|
@ -77,6 +74,8 @@ void Menu::processEvent(const sf::Event& event) {
|
|||
void Menu::frame() {
|
||||
// titre de la fenêtre
|
||||
getManager().setTitle("");
|
||||
getResourceManager().playMusic("menu.ogg");
|
||||
getWindow().setFramerateLimit(Manager::FPS);
|
||||
|
||||
// affichage du menu
|
||||
sf::RenderWindow& window = getWindow();
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
using dir_iter = boost::filesystem::directory_iterator;
|
||||
using fs_path = boost::filesystem::path;
|
||||
|
||||
ResourceManager::ResourceManager() : preloaded(false), music_volume(20) {
|
||||
ResourceManager::ResourceManager() : preloaded(false),
|
||||
music_volume(20), playing_state(false), current_music("") {
|
||||
// initialisation de la musique en bouclage et au volume par défaut
|
||||
music.setLoop(true);
|
||||
music.setVolume(music_volume);
|
||||
|
@ -114,6 +115,17 @@ std::vector<std::string> ResourceManager::getLevelList() {
|
|||
}
|
||||
|
||||
void ResourceManager::playMusic(std::string name) {
|
||||
// si la musique est déjà chargée, on la relance si elle
|
||||
// est en pause, sinon on ne fait rien
|
||||
if (current_music == name) {
|
||||
if (!playing_state) {
|
||||
playing_state = true;
|
||||
music.play();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// tente de charger la musique depuis le dossier "res/musics"
|
||||
std::string full_path = boost::filesystem::canonical(musics_path / name).string();
|
||||
std::cout << "Lecture de la musique " << name << "... ";
|
||||
|
@ -124,11 +136,17 @@ void ResourceManager::playMusic(std::string name) {
|
|||
std::cout << "OK!" << std::endl;
|
||||
}
|
||||
|
||||
current_music = name;
|
||||
playing_state = true;
|
||||
music.play();
|
||||
}
|
||||
|
||||
void ResourceManager::stopMusic() {
|
||||
music.stop();
|
||||
// on n'arrête la musique que si elle ne l'est pas déjà
|
||||
if (playing_state) {
|
||||
playing_state = false;
|
||||
music.stop();
|
||||
}
|
||||
}
|
||||
|
||||
float ResourceManager::getMusicVolume() {
|
||||
|
|
|
@ -26,6 +26,8 @@ void Rules::frame() {
|
|||
|
||||
// titre de la fenêtre
|
||||
getManager().setTitle(L"Règles");
|
||||
getResourceManager().playMusic("menu.ogg");
|
||||
getWindow().setFramerateLimit(Manager::FPS);
|
||||
|
||||
// on s'assure d'être dans la vue par défaut (pas de zoom, 0x0 en haut gauche)
|
||||
getManager().useGUIView();
|
||||
|
|
Loading…
Reference in New Issue