Author Topic: SOLVED: Strange sound help  (Read 1247 times)

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
SOLVED: Strange sound help
« on: Wed, Aug 6, 2014 »
(Using Flixel 2.34)

Ok, I've had some problems whittling this down before I brought it here, but I think it might be focused enough now for help.

Basically, the sound in my game is cutting in and out quite badly, but it is related to a couple specific objects that I create - a trap-generating system and the traps it creates.

I'm 99% positive that this has to do with how the looped sounds are implemented in these two classes. The strange thing is that the sound bug is somehow related to the player class. I do pass the player to them so they know its health/position/etc, but I do that with many other classes and don't have a problem with them.

I did a trace statement to see when the rocket sound I had was starting and stopping and oddly it seems to start the rocket sound when my player fires or does just about anything that makes a sound. This seems like a variable problem and I could really use some pointers, because the rocket sound should only stop playing when offscreen or when it dies.

It seems like it might also only be for certain sounds. The basic weapon doesn't play its sound or play it consistently when these objects are alive, but another weapon does.

Any ideas would be greatly appreciated. Both classes implement sound like this:

[Embed(source = "../../../data/rocket.mp3")] private var SndRocket2:Class;

//Trap function
Rocket = FlxG.play(SndRocket2, .5);
Rocket.stop();

//Trap update function

if (!Rocket.playing) Rocket = FlxG.play(SndRocket2, .5);
else if (!onScreen() && Rocket.playing) Rocket.stop();

//This is in another conditional that checks to see if it is OnScreen and a few other //things, but this isn't the problem since the other class doesn't have such a //conditional and it is also causing the problem.

Earlier I tried implementing sounds in a different way (don't recall now) and it seemed to have a similar bug related to the player class - causing some sounds the player started to loop for a while. Somehow the FlxSounds between the two are getting mixed up with each other.
         
« Last Edit: Tue, Aug 12, 2014 by Minverva »

c023-DeV

  • Game Artisan
  • Active Member
  • ***
  • Posts: 176
  • Karma: +0/-0
    • View Profile
    • DeV-ZoO
Re: Strange sound help
« Reply #1 on: Fri, Aug 8, 2014 »
Here is how I use sounds:

the vars:
private var AttackSound:FlxSound;
      private var IdleSound1:FlxSound;
      private var HurtSound1:FlxSound;
      private var DeathSound:FlxSound;
      private var RageSound:FlxSound;

the creation:


         RageSound = FlxG.loadSound(ZooAssetReg.audio_sfx_kadaver_rage01MP3, 1);
         AttackSound = FlxG.loadSound(ZooAssetReg.audio_sfx_kadaver_attack01MP3,1);
         IdleSound1 = FlxG.loadSound(ZooAssetReg.audio_sfx_kadaver_idle01MP3,1);
         HurtSound1 = FlxG.loadSound(ZooAssetReg.audio_sfx_kadaver_hit01MP3,1);
         DeathSound = FlxG.loadSound(ZooAssetReg.audio_sfx_kadaver_death01MP3,1);
         
Destroy:

         RageSound = null;
         AttackSound = null;
         IdleSound1 = null;
         HurtSound1 = null;
         DeathSound = null;


triggering:

AttackSound.proximity(x,y,Registry.player,250, true); AttackSound.play(true);



maybe that helps ? This way I kind of make sure that all classes have their own references to the sounds that need them... and for some sounds I have a global sound manager to make sure they only get played once or let me pick random sounds... not sure but that might help in your case?
If you aint got no dedication, you won't get no education!

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: Strange sound help
« Reply #2 on: Mon, Aug 11, 2014 »
Edit: Still not fixed actually

Thanks for trying, I think that code is for a later version of Flixel. Sorry for the late response, but I don't usually have time to code on the weekends.

I am going to make a more central location for assets in the future. I do it now with variables out of necessity but I didn't realize that every time I embedded something it added to the file size - even if the same file was embedded elsewhere.

I did end up fixing the problem with code like this:

//When creating
Rocket = new FlxSound().loadEmbedded(SndRocket2, false);

//When starting/restarting
Rocket = FlxG.play(SndRocket2, .5, true);

//When stopping/dying
Rocket.stop();

The weird thing is that I think this was my original code, but I changed it to try and fix another problem. It seems to be working fine now though, but I did change the name of the sound when embedding it under the theory that it was confusing it with the embeds used in other files.
« Last Edit: Mon, Aug 11, 2014 by Minverva »

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: Strange sound help
« Reply #3 on: Mon, Aug 11, 2014 »
The problem seems more rare now, which I assume means it is coming from elsewhere (I hope). I would still appreciate some insight on what causes these sound problems in general.

Minverva

  • Active Member
  • ***
  • Posts: 126
  • Karma: +0/-0
    • View Profile
Re: Strange sound help
« Reply #4 on: Tue, Aug 12, 2014 »
Doing "fadeOut" instead of "stop" seems to fix the problem.