我有以下数组:
var text = [
"RISE AND SHINE, JONATHON! HMM, ",
"THAT'S A MOUTHFUL, HOW ABOUT ",
"I JUST CALL YOU JOHN? MY ",
"NAME IS PROFESSOR ",
"PHIL. I BUILT YOU FROM ",
"SCRATCH. I WANT TO TELL YOU ",
"A LITTLE STORY BEFORE WE START."
];
然后我循环遍历数组:
for (var i = 0; i < 3; i++) {
this.font.draw(text[i]);
}
这显然输出:
RISE AND SHINE, JONATHON! HMM,
THAT'S A MOUTHFUL, HOW ABOUT
I JUST CALL YOU JOHN? MY
我需要帮助的是创建一个函数,它将遍历接下来的 3 行然后显示:
NAME IS PROFESSOR
PHIL. I BUILT YOU FROM
SCRATCH. I WANT TO TELL YOU
..等等。
这是我为 JavaScript/HTML5 游戏编写的聊天气泡代码,其中我的聊天对话在任何给定时间仅容纳 3 行文本。
一旦对话到达最后一句话。我希望它从头开始。