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:

define Pause
set volume to (0)%
set [pitch v] effect to ([log v] of ()) // keep the input blank

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

 set [pitch v] effect to ((-1) / (0)) // this equals -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:

define Resume
set volume to (100)%
set [pitch v] effect to (0)

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

Music

The music is optional:

when green flag clicked
forever
play sound (Music v) until done
end

External Links