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

Author Topic: Added sound to program, now just getting white screen.  (Read 3743 times)

0 Members and 1 Guest are viewing this topic.

stuart88

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Added sound to program, now just getting white screen.
« on: February 26, 2017, 05:04:07 pm »
So my programs works fine, and now I'm just upgrading it by toying with sound for the first time. However, what appears to be quite a simple attempt at importing and using a sound file is resulting in the program opening to a white screen.

Does anyone know what could be causing this?

The tiny amount of sound-related code I'm using is below:

        sf::Music wind1;
        wind1.openFromFile("ambient-loop2.wav");
        wind1.setLoop(true);
        int vol = 50;
        wind1.setVolume(vol);
        wind1.play();

This code is inside int main, but not inside the main game loop. I think I may be going wrong with that aspect - I'm not sure where I'm supposed to create the Music and then tell it to play.

As an aside, my aim is to make it so that the volume changes in unison with another parameter in the project - getting louder or quieter as the parameter value changes. It's currently setup to update the volume just before all the calls to draw all the new sprites at the end of each loop.

However, the program doesn't get any further than a white screen now anyway.

Hints appreciated, thanks.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Added sound to program, now just getting white screen.
« Reply #1 on: February 26, 2017, 05:45:48 pm »
Run a debugger and find out what us going on. Without the complete code it's impossible for us to tell what is or isn't happening.
« Last Edit: March 15, 2017, 10:28:04 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

stuart88

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Added sound to program, now just getting white screen.
« Reply #2 on: February 26, 2017, 05:56:06 pm »
I have absolutely no idea what I did, but the problem seems to have righted itself!

Code is still in the same spot of the script and I didn't make any wild changed to it, yet now everything runs fine, with sound.

Probably a typo somewhere.

Thanks, and apologies for making this waste of a thread  :-[

eigen

  • Jr. Member
  • **
  • Posts: 64
  • Brobdingnagian ding dong
    • View Profile
    • Pioneersgame.com
Re: Added sound to program, now just getting white screen.
« Reply #3 on: March 15, 2017, 10:17:09 pm »
How long is the WAV file? Maybe it just takes a long time to load and blocks your execution until then. I've noticed the WAV file loading has slowed down a lot (in 2.4.1 compared to 2.3.2).
« Last Edit: March 15, 2017, 10:45:06 pm by eigen »