+1 vote
asked by (1.1k points)

Hello peoples!

I am using SugarCube 2.21.0, displaying images like so:


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

Thank you in advance!


2 Answers

0 votes
answered by (59.9k 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>>


commented by (1.1k 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
answered by (22.3k 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>>

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

commented by (1.1k points)
Wonderful! That should work I believe. Thank you for the help!
commented 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.

commented by (1.1k 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?
commented 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.

commented by (1.1k points)
Thank you! It is good to have more than one thing to try.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.