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?
我想做一个教程页面,其中的主要字符给出了语音泡泡。假设,我使用UILabel/UITextView来包含这些演讲,我如何使文本像rpg教程场景那样逐字显示?
Thank you.
谢谢你!
2 个解决方案
#1
2
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.)
(例如,元素0可能是@“嘿,欢迎来到教程!”,元素1可能是@“这个游戏的目标是…”等等。
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.
然后,我建议使用UIButton循环文本,这样当用户触碰屏幕时,你的角色将继续“说话”。
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.
为此,只需在Interface builder/Xcode中创建一个按钮,将其放大到包括整个屏幕,并将显示模式设置为custom,使其不可见。
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.
您可能希望将它发送回(命令在布局中),以便您可以与nib文件的其余部分进行交互。
Link the button to an IBAction
function along the lines of the following:
将按钮链接到IBAction函数,如下所示:
-(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!
希望这可以帮助!
#2
1
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.
手绘文本,按位置(第n个字符,等等)标记每个单词或短语,以及希望它相对于最后一个字符出现的时间。然后使用一个NSTimer。每次计时器停止时,将文本中的一个越来越大的子字符串(到n -1字符)放入textview的内容中。然后重新设置下一个单词或短语的计时器。
#1
2
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.)
(例如,元素0可能是@“嘿,欢迎来到教程!”,元素1可能是@“这个游戏的目标是…”等等。
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.
然后,我建议使用UIButton循环文本,这样当用户触碰屏幕时,你的角色将继续“说话”。
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.
为此,只需在Interface builder/Xcode中创建一个按钮,将其放大到包括整个屏幕,并将显示模式设置为custom,使其不可见。
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.
您可能希望将它发送回(命令在布局中),以便您可以与nib文件的其余部分进行交互。
Link the button to an IBAction
function along the lines of the following:
将按钮链接到IBAction函数,如下所示:
-(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!
希望这可以帮助!
#2
1
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.
手绘文本,按位置(第n个字符,等等)标记每个单词或短语,以及希望它相对于最后一个字符出现的时间。然后使用一个NSTimer。每次计时器停止时,将文本中的一个越来越大的子字符串(到n -1字符)放入textview的内容中。然后重新设置下一个单词或短语的计时器。