Writing Marquee Text |
This fun and easy little function (ahem) writes out a word letter by letter. Open up the local variables in the parameters to enter the text. The steps parameter controls how many frame each letter is visible. Just copy the text below and paste it into the Node View with Ctrl+V. Text1 = Text(720, 486, 1, {{ string logo = myText; stringf("%c",\nlogo[(int) clamp((time-1)/steps, 0,strlen(logo))]) }}, "Courier", 100, xFontScale, 1, width/2, height/2, 0, 2, 2, 1, 1, 1, 1, 0, 0, 0, 45, string myText = "Yadda Yadda Yadda", int steps = 3 ); Within the Text field the variable "logo" is defined as linked to myText, the string "Yadda Yadda Yadda". Using the Shake stringf function (similar to printf) you can represent any character of the string as %c. Using the syntax logo[(int)time] the %c will use time to specify which character is printed depending on the value of the current frame. "time" is a built in Shake variable that passes the current frame number. (int) is used to force the value of time to an integer since the position of a character cannot be floating point. You actually need to use "time-1" because the first character of "logo" is actually position 0 not 1. We divide that by the variable "steps" so that we can control for how many frames the letters are on screen. The rest of the syntax "clamp((time-1)/steps, 0,strlen(logo))" is to act as a safeguard. You wouldn't want to pass a value that is less than 0 or more than the length of the string because if the index goes out of the string we pick up whatever byte is in memory before or after the string (garbage), or we crash because we try to access a memory area that doesn't belong to us (this is the case if the string is stored exactly at the end of the memory segment we own). To guarantee safety we use the clamp function, clamping "time-1" to be between 0 and strlen(logo). strlen() determines the size of the string automatically. Wasn't that easy? |