Modding Resources: Installing Mods | Creating Mods | Basic Code Examples | Creating a Character | Audio and Visual Effects | The Automator | User Interface | Graph Editor

Audio & Visual Effects

Using Sounds

See ExampleCharacterMain.as in the Clicker Heroes 2\mods\examples folder for a mod made using the code described here.

If you want to have a sound play you will need to have your character load the sounds you want to use within the onCharacterDisplayCreated function.

First you will need to import heroclickerlib.world.CharacterDisplay and heroclickerlib.managers.SoundManager. Then you will need to override the default onCharacterDisplayCreated function, as described in the section, Overriding Character Functions. Here is an example that will load the default attack sounds:

	
	public function onCharacterDisplayCreatedOverride(display:CharacterDisplay):void
	{
		SoundManager.instance.loadAudioClass("audio/HelpfulAdventurer/critical_hit");
		SoundManager.instance.loadAudioClass("audio/HelpfulAdventurer/hit");
	}
	

You will also need to set your mod as the handler of the onCharacterDisplayCreated function. Here is an example that does this for the example character created in the Creating a Character section:

	
	public function onCharacterCreated(characterInstance:Character):void 
	{
		if (characterInstance.name == "Example Character") 
		{
			characterInstance.onCharacterDisplayCreatedHandler = this;
		}
	}
	

Since characters are set up to use these sounds by default, your character will use them automatically after they are loaded, without you needing to do anything else. But what if we want to add a sound to something else, a custom skill for example?

First we will need to load the sound we want to use in the setUpDisplay function we created just like before. Here is another example, again using an audio file that comes with the game:

	
	SoundManager.instance.loadAudioClass("audio/HelpfulAdventurer/power_surge_activate");
	

The above code will load the sound file located in the named directory in the main Clicker Heroes 2 install folder. You can find the pre-installed sound files in the Clicker Heroes 2\audio folder. In this case, we're using the Powersurge sound effect. By default the full path of where you can find this file will be something like this:

    C:\Program Files (x86)\Steam\steamapps\common\Clicker Heroes 2\audio\HelpfulAdventurer\power_surge_activate\

Once the sound file has been loaded, you can now play it with the following line of code:

	
	SoundManager.instance.playSound("power_surge_activate");
	

One way to use sounds is with skills. For example, we can have this sound play when we use the example skill we created in the Creating a Skill section by adding the above line to its effect function:

	
	private function exampleEffect():void 
	{
		var monster:Monster =  CH2.world.getNextMonster();

		if (monster) 
		{
			var attackData:AttackData = new AttackData();
			var damageNumber:BigNumber = new BigNumber(100);    

			attackData.damage = damageNumber;                
			CH2.currentCharacter.attack(attackData);

			SoundManager.instance.playSound("power_surge_activate");
		}
	}	
	
Adding Custom Sounds

So far we've been looking at examples that use sounds that come with the game, but you can also add a new sound in .mp3 format. You will need to name your sound file 1.mp3 and put it in a custom folder inside the mods\active folder where you install your swf files. The location should be something like this:

    Clicker Heroes 2\mods\active\YourModName\example_sound\1.mp3

You can now access your new sound in code using "mods/active/YourModName/example_sound" in place of where we used "audio/HelpfulAdventurer/power_surge_activate" in the above examples. You will need to include any custom folders and sound files with your mod if you distribute it to other players and instruct them to install them in the mods\active folder along with the swf.

Using Visual Effects

See ExampleCharacterMain.as in the Clicker Heroes 2\mods\examples folder for a mod made using the code described here.

For now you can use the graphical assets that are included in the game by using the getGpuMovieClip function to get an animation and then add it to the world. Here is an example that adds a visual effect to the example effect created in the Creating a Skill section.

	
	private function exampleEffect():void 
	{
		var monster:Monster =  CH2.world.getNextMonster();

		if (monster) 
		{
			var attackData:AttackData = new AttackData();
			var damageNumber:BigNumber = new BigNumber(100);

			attackData.damage = damageNumber;
			CH2.currentCharacter.attack(attackData);

			var effect:GpuMovieClip = CH2AssetManager.instance.getGpuMovieClip("HelpfulAdventurer_bamplode1");
			effect.gotoAndPlay(1);
			effect.isLooping = false;
			CH2.world.addEffect(effect, CH2.world.roomsFront, monster.x, monster.y);
		}
	}
	

The above example gets the effect "HelpfulAdventurer_bamplode1", sets it to start playing at frame 1 with the gotoAndPlay function, and then sets it as not looping (ie. repeating). Finally, it adds the effect to the world at the location of the next monster using the addEffect function.