lisp.get("volume" ,maximumvolume );
// set dimension to zero if smaller than 64, which is default size in flexlay
lisp.get("volume" ,maximumvolume );
// set dimension to zero if smaller than 64, which is default size in flexlay
lisp.get("silence_distance",silence_distance);
sound_source = 0; // not playing at the beginning
lisp.get("silence_distance",silence_distance);
sound_source = 0; // not playing at the beginning
sound_source = sound_manager->create_sound_source(sample);
if(!sound_source)
throw std::runtime_error("file not found");
sound_source = sound_manager->create_sound_source(sample);
if(!sound_source)
throw std::runtime_error("file not found");
sound_source->play();
} catch(std::exception& e) {
log_warning << "Couldn't play '" << sample << "': " << e.what() << "" << std::endl;
sound_source->play();
} catch(std::exception& e) {
log_warning << "Couldn't play '" << sample << "': " << e.what() << "" << std::endl;
- // Player position
- px=Sector::current()->player->get_pos().x;
- py=Sector::current()->player->get_pos().y;
+ if (!Sector::current() || !Sector::current()->camera) return;
+ // Camera position
+ px=Sector::current()->camera->get_center().x;
+ py=Sector::current()->camera->get_center().y;
// calculate target volume - will never become 0
targetvolume=1/(1+sqrdistance*distance_factor);
float rise=targetvolume/currentvolume;
// rise/fall half life?
currentvolume*=pow(rise,deltat*10);
// calculate target volume - will never become 0
targetvolume=1/(1+sqrdistance*distance_factor);
float rise=targetvolume/currentvolume;
// rise/fall half life?
currentvolume*=pow(rise,deltat*10);
sound_source->set_gain(currentvolume*maximumvolume);
if (sqrdistance>=silence_distance && currentvolume<1e-3)
sound_source->set_gain(currentvolume*maximumvolume);
if (sqrdistance>=silence_distance && currentvolume<1e-3)