Skip to content

Instantly share code, notes, and snippets.

@AJpon
Created August 21, 2020 09:53
Show Gist options
  • Save AJpon/c58c172bba471d507f858eb3470fa88d to your computer and use it in GitHub Desktop.
Save AJpon/c58c172bba471d507f858eb3470fa88d to your computer and use it in GitHub Desktop.
昔のADVゲームやRPGゲームでよく見かけたテキスト表示を行う最低限のプログラム
String str = "abcdefg";
int textSize = 60;
int intervalTime = 120; // 文字の表示間隔をミリ秒で指定
void setup() {
size(300, 100);
textSize(textSize);
fill(248);
}
void draw() {
background(0);
int endIndex = min(millis()/intervalTime, str.length()); // 何文字目まで表示するのかを計算
text(str.substring(0, endIndex), 0, textSize); // 実際に文字を表示
}
@AJpon
Copy link
Author

AJpon commented Aug 21, 2020

補足

昔のゲームでは文字の表示に合わせて効果音が鳴ったりもしましたが、その辺も再現したい場合はもう少し工夫が必要です

  • intervalTime の値を変更すると文字の表示速度が変化します
  • 実際に表示を行う上で肝になるのは13~14行目の部分です

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment