Pause and Resume Music

Материал из Поле цифровой дидактики

This tutorial will explain how to make resume/pause custom blocks that give users the ability to pause and resume sounds in a project.

Pausing Sounds

This script will make sounds pause:

definePausesetvolumeto0%setpitcheffecttologofkeeptheinputblank

Another way this can be done is to put this block at the end, which still has the same effect:

setpitcheffectto-1/0thisequals-infinity

This works because the pitch effect blocks can slow down and speed up sounds. However, the minimum the pitch effect can go is a value -360, meaning that it is impossible to fully pause sounds using the pitch effect blocks. That is the reason the set volume to 0 block is needed, otherwise the sound would still be heard. While it may be impossible to fully pause sounds this way, this method will still get very close.

Resuming Sounds

This script will make the sounds resume:

defineResumesetvolumeto100%setpitcheffectto0

This code just reverts the effects of the "pause sound" custom block.

Music

The music is optional:

whenclickedforeverplaysoundMusicuntildoneend

External Links