Jin
Jin

Reputation: 143

How to animate text to appear word by word for iphone app?

I want to do up a tutorial page with the main character giving speech bubbles. Suppose, I use UILabel/UITextView to contain those speeches, how do I animate the text to appear word by word like what we see in a rpg tutorial scene?

Thank you.

Upvotes: 3

Views: 2137

Answers (2)

Nicholas1024
Nicholas1024

Reputation: 890

Go through the text you're planning, and partition it into an array, such that each element of the array would be a block of text you want your character to say.

(For example, element 0 might be @"Hey there, welcome to the tutorial!", element 1 might be @"The goal of this game is..." and so on.)

Then, I'd recommend using a UIButton to cycle through the text, so that your character will continue "speaking" when the user touches the screen.

To do this, simply create a button in Interface builder/Xcode, enlarge it to include the whole screen, and set the display mode to custom, making it invisible.

You may want to send it to back (The command is under Layout) so you can interact with the rest of your nib file though.

Link the button to an IBAction function along the lines of the following:

-(IBAction) continueTutorial{
    i ++; //Here i is an NSInteger from your .h file, set it to 0 when the tutorial starts
    YourUILabel.text = [yourArray objectAtIndex: i];
}

Hope this helps!

Upvotes: 2

hotpaw2
hotpaw2

Reputation: 70683

Go through the text by hand and mark each word or phrase by position (nth character, etc.) and the time you want it to appear relative to the last. Then use an NSTimer. Each time the timer goes off, put a larger and larger substring (to the nth-1 character) from your text into your textview's contents. Then (re)set the timer for the next word or phrase.

Upvotes: 1

Related Questions