Player sounds
Author(s): benevolusgoatTags:
When creating custom characters, it may be desired to alter the sound effect that normally plays for taking damage and dying to better fit the new character. While this can be achieved with relative ease, there is importance in supporting more than one character so it only plays for your character when appropriate.
As this tutorial will be covering usage of a custom character and sound effect, please see the articles for creating new characters and sound effects for reference.
Non-REPENTOGON method⚓︎
Without REPENTOGON, replacing sounds for individual characters must be done with Lua code. The best method of replacing the sounds for only select characters are knowing when they will play and playing your new sound afterwards.
Note
Due to the limitations of the vanilla API, you may hear a split second of the original sound before it stops and your new sound plays. There are more "hacky" methods that involve replacing the original sound files, but they will not be covered in this tutorial.
Hurt sound detection⚓︎
The first step is to build the code that will detect when the sounds should be played. The code involved with actually replacing the sounds will be done within a function that, for now, will be left empty and revisited later.
For the hurt sound effect, it plays each time Isaac gets hurt. For this, only the MC_ENTITY_TAKE_DMG callback is required.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
Death sound detection⚓︎
The death sound effect plays when the "DeathSound" event is triggered. You can view 001.000_player.anm2 inside the game's extracted resources and see that it's placed within all of the available death animations.

MC_POST_PEFFECT_UPDATE will be used to constantly check when the DeathSound event triggers on the player's sprite in order to play the death sound effect. Both this callback and the game's logic run at 30 frames per second, as opposed to MC_POST_PLAYER_UPDATE which runs at 60 frames per second. Since we only need to check once every game update, MC_POST_PEFFECT_UPDATE is preferrable.
1 2 3 4 5 6 7 8 9 10 | |
The body left behind by the "Lost Curse" effect, triggered by the White Fireplace and Soul of the Lost, is a separate entity that will also play the sound. It will leave behind a devil statue effect (EffectVariant.DEVIL), replace its anm2 file with your character's anm2 file, and play the Death animation. As such, an additional callback is needed to account for this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
Replacing the sounds⚓︎
Now that the code to detect when the sound should play for your character is operating, we must write the replacePlayerSound function from earlier. The oldSound argument will be used for both stopping the old sound and knowing what new sound to play. However, there are a few quirks to make note of:
MC_ENTITY_TAKE_DMGruns before the entity sustains the damage, and thus the hurt sound effect has not played yet.- The death sound effect for when the player dies (not for the Lost Curse) plays twice for an unknown reason, so stopping it once will not stop it fully.
- For both the player and dead player body's death sounds, by the time the DeathSound sprite event is triggered, the death sound should be already playing.
For all of these cases, the FrameDelay and Volume parameters for SFXManager():Play will be utilized. FrameDelay will stop the sound from playing again for however many frames it is set to, and Volume will adjust the volume of the sound.
FrameDelay by default is already 2, and by setting the Volume to 0, a silent sound effect can be played that cannot be overridden on the next game update. This will be used to stop the vanilla hurt and death sounds from playing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
REPENTOGON method⚓︎
REPENTOGON on Repentance+ users can use a much simpler method of adding sounds to your custom character that involves zero Lua code. Within the players.xml file, you can define two new variables:
| Variable Name | Value | Comment |
|---|---|---|
| hurtsound | number or string | Any instance of the character playing SoundEffect.SOUND_ISAAC_HURT_GRUNT will be replaced with the new sound |
| deathsound | number or string | Any instance of the character playing SoundEffect.SOUND_ISAACDIES will be replaced with the new sound |
The following example replaces the custom character's hurt sound with SoundEffect.SOUND_LEECH and the death sound with a custom sound effect named "My Death Sound":
sounds.xml
1 2 3 4 5 | |
players.xml
1 2 3 4 5 6 7 8 9 | |