+1 vote
by (1.4k points)

Hello peoples!

I am using SugarCube 2.21.0, displaying images like so:

[img[image-url]]

Is there something that can make a sound play when the image is clicked?

Thank you in advance!

Patrick

2 Answers

0 votes
by (63.1k points)
selected by
 
Best answer

Assuming you have the sound all setup up properly using <<cacheaudio>> et al, just use a <<link>> macro.

<<link [img[image-url]]>>
    <<audio 'track-name' play>>
<</link>>

 

by (1.4k points)
Thank you!

I was concerned this would make the passage reload or have to go to another passage, but wonderfully not.

Is there a way to have the image be replaced by another image without reloading or changing the passage?
0 votes
by (23.6k points)

Use the <<link>> macro and just put the audio macro you need in there. Like this:

<<link [img[yourimage.jpg][PassageName]]>>
<<audio "your_audio" play>>
<</link>>

Don't forget to add the audio via  <<cacheaudio trackId sourceList>> in StoryInit.

by (1.4k points)
Wonderful! That should work I believe. Thank you for the help!
by (2.7k points)

Sorry I meant <<linkreplace>> - <<clickreplace>> is the sugarcube V1 version.
Here is an example:

<<linkreplace "Title">><<dosomething>>Text<</linkreplace>>

Where <<dosomething>> can be replaced by any macro and "Text" by any text. "Title" will be the title of the link.

by (1.4k points)
So you would put the first image in as the link title, and when that image is clicked it would be replaced by an image you would put in as the text, and the audio macro would play audio, correct?
by (2.7k points)

Correct. If you want the image to disappear or be replaced by another, then this is the correct solution. If you want it to remain, and be able to be clicked multiple times, use Chapel's answer.

by (1.4k points)
Thank you! It is good to have more than one thing to try.
...