闪光的ActionScript 3.0打字机Dialiouge盒 [英] Flash ActionScript 3.0 Typewriter Dialiouge Box
问题描述
所以这可能是一个非常简单的答案,但我不知道这一点。我想提出一个游戏,该对话框有这种打字机的效果,我想,因为它进入另一个框架的文本改变。 (textF是我的实例名称为动态文本框)。
So This may be a very simple answer, but I cannot figure this out. I am making a game where the dialogue box has this typewriter effect and I want the text to change as it enters another frame. (textF is my instance name for the dynamic text box).
var myString:String = "Howdy Howdy Howdy Howdy\n\n Howdy";
var myArray:Array = myString.split("")
addEventListener(Event.ENTER_FRAME, frameLooper);
function frameLooper(event:Event): void {
if (myArray.length > 0) {
textF.appendText(myArray.shift());
}
else {
removeEventListener(Event.ENTER_FRAME, frameLooper);
}
}
现在我想从你好......喜欢更改文本然后太阳从东方升起,当它进入下一帧。
Now I want to change the text from "Howdy..." to like "And then the sun rises in the east" when it enters the next frame.
我如何$ C c表示$?由于任何人谁可以回答这个...如果我迷惑,我能改写这个问题。
How do I code that? Thanks to anyone who can answer this... and if I'm confusing, I could reword this question.
推荐答案
有很多方法可以做到这一点。由于您使用的是 ENTER_FRAME
事件,这里有一个相对的工作例如:
There are many ways you can do this. Since you are using an ENTER_FRAME
event, here's a relative working example:
//Create 3 variables, 1 for your current text, time, and speed
import flash.utils.getTimer;
//remove access modifiers if you are doing this in the timeline
private var beginTime:Number;
private var currentText:String
private const SPEED:int = 100;
//set the current text and begin time, then add your listener
beginTime = getTimer();
currentText = "Howdy...And then the sun rises in the east";
addEventListener(Event.ENTER_FRAME, frameLooper);
//then in your frameLooper()
function frameLooper(event:Event): void {
//add character at index 0 of currentText
if ( getTimer() - beginTime >= SPEED ) {
beginTime = getTimer();
textF.appendText( currentText.slice(0, 1) );
currentText = currentText.substr( 1, currentText.length );
}
}
您可以调整速度
不变,以任何你喜欢的。这是使用与您当前的想法做的只是一种方法 ENTER_FRAME
事件。
You can adjust the SPEED
constant to whatever you like. This is just one way of doing it with your current idea using ENTER_FRAME
event.
另外,如果你想有一个更真实的打字机效果,你可以把速度
非常变量,然后里面的if语句如果(的getTimer() - BEGINTIME> = SPEED)
,你可以用随机的速度变量:
Also if you want a more realistic type writer effect, you could make SPEED
a non constant variable, and then inside the if statement if ( getTimer() - beginTime >= SPEED )
you could randomize the SPEED variable with:
SPEED = Math.floor( Math.random() * ( 200 - 100 ) + 100 );
这会为您提供不同的速度在100-200ms的范围内,你可以改变周围。
That would giving you varying speeds in the range of 100-200ms which you can change around.
这篇关于闪光的ActionScript 3.0打字机Dialiouge盒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!