What happens after fp.world = new (insert new world)


(Adam Edney) #1

Is there a override in a object before the world gets changed because I have a tower which make a sound but if I change the world before the sound has completed the sound continues, even if I stop the sound on the same frame that the world is changed the sound stills continues. Know why ?


(Mike Evmm) #2

May be going out on a limb here a bit, but:

  1. From the documentation/tutorials:

Assigning FP.world does not immediately change the active World, but instead sets an internal flag to change the World at the end of the frame. So the World will not actually be switched until the current frame in your game loop has completed.

So, stopping the sound before the end of the frame/loop like you suggested should work.

and 2) there is the end() function of a world, which can be overridden and is called at the change from that world to another. If you want to stop a sound on world exit, you can do something along the lines of:

override public function end():void{
    if (mySfx!=null) mySfx.stop();
}

P.S.: To answer the question in the title, right before FP.world = new World() is executed `end()` of the "old" world is called, and, right afterwards, `begin()` of the "new" world is called.

(Adam Edney) #3
  	override public function end():void 
	{
                for each (var tower:TOWER in tower_array)
		{
			tower.sound.stop();
		}
		super.end();
	}

This what I got now, but the sound of the tower is still playing after i change world, and i’m not too sure why .


(Mike Evmm) #4

Huh, strange. When do you populate tower_array? Try adding a getType() to the top of the function.


(Adam Edney) #5

Yh still not working, even if i do it directly inside the tower (p.s. even .volume is not working because there no difference between .volume = 1 or .volume = 0.01.)


(Mike Evmm) #6

Really weird. Can I take a look at your sound code?


(Adam Edney) #7

sure (here a simple version of the code because the real version is 500 line long for the tower)

 public var flame_thrower_sound:Sfx = new Sfx(ASSET_IMG.FLAME_THROWER_SOUND);
	
 public class BLUE_FLAME_THROWER extends Entity implements TOWER
 {
 public function BLUE_FLAME_THROWER()
 {
   flame_thrower_sound.volume = 0.0;
 }

  public function fire():void
  {
     flame_thrower_sound.play();
  }
 public function remove_tower():void
  {
     flame_thrower_sound.stop();
  }
}

and then in the world in the override end

  override public function end():void
  {
     flame_thrower_tower.remove_tower();
  }

(Mike Evmm) #8

Everything looks okay. I’m sorry, but I have no idea what might be wrong :confused:

One last thing, you’ll probably want to set the volume when playing it instead of earlier, like sound.play(0.4) . Maybe that has something to do with the volume issue.


(Zachary Lewis) #9

Throw a trace in your sound stop iteration. I have a feeling that end() is called after all the entities are removed from the world.

Try stopping your sounds before changing worlds with FP.world = new World().


(Adam Edney) #10

here is the trace list

 sound start
 sound stop function is called 
 sound start
 sound start
 end() is started 
 sound stop function is called 
 sound stop function is called 
 sound stop function is called 
 end() super is called 

also if

 Main_Music.play(0);

this should mean that i cant hear it but I can