+2 votes
by (3.5k points)
I am looking for a way to animate the text of the passage.
For example, in a sentence "How are you?" and I want the letters W and Y to loop through certain characters so that after each second it would change to "Hoj are cou?" and then "Hoj are dou?". Ho(w->c->r->w again (looping)) are (y->c->d->y again (looping)).
Is there any way something like this could be done?

Any help will be greatly appreciated :^))

1 Answer

0 votes
by (340 points)

There are definitely ways to do this. 

In the sentence "How are you?" you can add hooks for the letters you want to change. Like so: 

Ho[w]<hook1| are [y]<hook2|ou?

Then you can use the (live:) macro to replace the contents of the hook with various things. Sorry if the below approach seems confusing. 

First set up an array of the characters you want replacing the hook: 

(set:$hook1_replacement_chars to (a:"c","r","w")) 

Then, using a (live:) macro, which repeats on the basis of time you give it, use an index to loop through the array above. Inside the loop, increment the index, and then use a modulus to keep the index giving you 1, 2, 3, replacing the characters in an endless loop: 

(set:$index to 1)
(live:1s)[(replace:?hook1)[$hook1_replacement_chars's ($index % 3 + 1)]
(set:$index to ($index + 1)]

You'd have to set up one of these for each hook. Hope it's worth it, haha... 

by (158k points)

WARNING: The (live:) macro creates a timer thread which is used to execute the content of the that macro call's associated hook, and each time that execution occurs it interfers with that end-user's ability to interacte with page. The effect that interference may have depends on things like: the shortness of the delay period being used; the number of (live:) macros you have active simultaneously, and the complexity of the code within the associated hook(s).

This means some care needs to be used when using a (live:) macros to animate a portion(s) of the page.

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.
...