#3
by Yuki_256 » 1年前
すみません。説明が抽象的すぎました!
というより日本語がおかしかったです。
下のコードを参考にすると、
コード:
int Key[256];
int UpdateKey() { //押されたキーを判定する
char tmpKey[256]{};
GetHitKeyStateAll(tmpKey);
for (int i = 0; i < 256; i++) {
if (tmpKey[i] != 0) {
Key[i]++;
}
else {
Key[i] = 0;
}
}
return 0;
}
int FileHandle;
char String[50][100]{}; //[最大の行数][1行あたりの最大文字数]
//textファイルを用意する関数
void Text_File() {
//textファイルを開く
FileHandle = FileRead_open("テキスト.txt");
for (int i = 0; i < 49; i++) {
FileRead_gets(String[i], 256, FileHandle);
}
FileRead_close(FileHandle);
}
int DrawWidth;
bool EnterPressed = false;
int Text(int x) {
if (Key[KEY_INPUT_RETURN] == 1) { //キーが押されたらtrueにする
EnterPressed = true;
}
if (EnterPressed) { //EnterPressed == trueなら
DrawWidth = GetDrawStringWidth(String[0], -1);
DrawString((640 - DrawWidth) / 2, 220, String[0], GetColor(255, 255, 255)); //文字を消す(ファイル内の0行目は空白)
}
else {
DrawWidth = GetDrawStringWidth(String[x], -1); //文字を中央揃えにする
DrawString((640 - DrawWidth) / 2, 220, String[x], GetColor(255, 255, 255)); //xの値によって表示させる行数を変える
}
return x;
}
int WINAPI WinMain(_In_ HINSTANCE hinstance, _In_opt_ HINSTANCE hPrevInstance,_In_ LPSTR lpCmdLine,_In_ int nShiwCmd)
{
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 && UpdateKey() == 0){
Text_File(); //txtファイルを読み込む
Text(1); //txtファイルの1行目を表示する
Text(2); //txtファイルの2行目を表示する
}
DxLib_End();
return 0;
}
本来はText(1)を先に動かして、その後にText(2)を動かしたかったのですが、最初からText(1),Text(2)の両方が動いてしまって文字が重なってしまいます。
この原因は文字を消す部分のプログラムに問題があるのかと思い、質問しました。
このコードを参考にしていただき、さらに改善案を出していただければ幸いです。
まだ少し日本語が怪しい部分がありますが、すみません。
すみません。説明が抽象的すぎました!
というより日本語がおかしかったです。
下のコードを参考にすると、
[code]
int Key[256];
int UpdateKey() { //押されたキーを判定する
char tmpKey[256]{};
GetHitKeyStateAll(tmpKey);
for (int i = 0; i < 256; i++) {
if (tmpKey[i] != 0) {
Key[i]++;
}
else {
Key[i] = 0;
}
}
return 0;
}
int FileHandle;
char String[50][100]{}; //[最大の行数][1行あたりの最大文字数]
//textファイルを用意する関数
void Text_File() {
//textファイルを開く
FileHandle = FileRead_open("テキスト.txt");
for (int i = 0; i < 49; i++) {
FileRead_gets(String[i], 256, FileHandle);
}
FileRead_close(FileHandle);
}
int DrawWidth;
bool EnterPressed = false;
int Text(int x) {
if (Key[KEY_INPUT_RETURN] == 1) { //キーが押されたらtrueにする
EnterPressed = true;
}
if (EnterPressed) { //EnterPressed == trueなら
DrawWidth = GetDrawStringWidth(String[0], -1);
DrawString((640 - DrawWidth) / 2, 220, String[0], GetColor(255, 255, 255)); //文字を消す(ファイル内の0行目は空白)
}
else {
DrawWidth = GetDrawStringWidth(String[x], -1); //文字を中央揃えにする
DrawString((640 - DrawWidth) / 2, 220, String[x], GetColor(255, 255, 255)); //xの値によって表示させる行数を変える
}
return x;
}
int WINAPI WinMain(_In_ HINSTANCE hinstance, _In_opt_ HINSTANCE hPrevInstance,_In_ LPSTR lpCmdLine,_In_ int nShiwCmd)
{
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 && UpdateKey() == 0){
Text_File(); //txtファイルを読み込む
Text(1); //txtファイルの1行目を表示する
Text(2); //txtファイルの2行目を表示する
}
DxLib_End();
return 0;
}
[/code]
本来はText(1)を先に動かして、その後にText(2)を動かしたかったのですが、最初からText(1),Text(2)の両方が動いてしまって文字が重なってしまいます。
この原因は文字を消す部分のプログラムに問題があるのかと思い、質問しました。
このコードを参考にしていただき、さらに改善案を出していただければ幸いです。
まだ少し日本語が怪しい部分がありますが、すみません。