こんにちは。私は今イメージファイルで問題を出して答えを入力してもらうプログラムをDXLibで具現しています、
初心者なので機能を一つ追加するたびに困っていますが、現在は画面の切り替えに困っています。
ボタンを押すと画面が切り替わりたいのですが、2番目の画面が点滅します。 手伝ってもらえますか?
足りないコードを添付してみます。
main.cpp:
#include "DxLib.h"
#include "SCENE.h"
#include "PROBLEMSOLVER.h"
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
ChangeWindowMode(TRUE);
if (DxLib_Init() == -1)
{
return -1;
}
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0)
{
switch (currentScene) {
case SCENE_FIRST:
FirstScreen();
break;
case SCENE_SECOND:
SecondScreen();
break;
case SCENE_THIRD:
ThirdScreen();
break;
case SCENE_FOURTH:
case SCENE_FIFTH:
case SCENE_SIXTH:
case SCENE_SEVENTH:
case SCENE_EIGHTH:
case SCENE_NINTH:
break;
default:
break;
}
ScreenFlip();
}
DxLib_End();
return 0;
}
Scene.cpp:
#include "DxLib.h"
#include "SCENE.h"
#include "PROBLEMSOLVER.h"
SceneType currentScene = SCENE_FIRST;
void ChangeScene(SceneType newScene) {
currentScene = newScene;
}
void FirstScreen()
{
int backgroundImage = LoadGraph("C:/Users/user/Desktop/source/repos/DXlib/Data/background.png");
int bgX = 0, bgY = 0;
int font = CreateFontToHandle("~", 30, 3, DX_FONTTYPE_EDGE);
int buttonFont = CreateFontToHandle("~", 30, 3, DX_FONTTYPE_NORMAL);
int img1 = LoadGraph("C:/Users/user/Desktop/source/repos/DXlib/Data/1.png");
int img2 = LoadGraph("C:/Users/user/Desktop/source/repos/DXlib/Data/2.png");
int x1 = 100, y1 = 200;
int x2 = 500, y2 = 200;
double angle = 0.0, scale = 0.5;
int buttonX = 200;
int buttonY = 200;
int buttonWidth = 150;
int buttonHeight = 80;
const char* buttonText = "START!";
DrawGraph(bgX, bgY, backgroundImage, TRUE); //배경
DrawRotaGraph(x1, y1, scale, angle * DX_PI / 180, img1, 1);
DrawRotaGraph(x2, y2, scale, angle * DX_PI / 180, img2, 1);
DrawFormatStringToHandle(120, 150, GetColor(255, 255, 255), font, "~");
DrawBox(buttonX, buttonY, buttonX + buttonWidth, buttonY + buttonHeight, GetColor(128, 128, 128), TRUE);
DrawStringToHandle(buttonX + 15, buttonY + 20, buttonText, GetColor(255, 255, 255), buttonFont);
if (GetMouseInput() & MOUSE_INPUT_LEFT) {
ChangeScene(SCENE_SECOND);
}
}
void SecondScreen()
{
int s_backgroundImage = LoadGraph("C:/Users/user/Desktop/source/repos/DXlib/Data/background.png");
int s_bgX = 0, s_bgY = 0;
int s_font = CreateFontToHandle("~", 30, 3, DX_FONTTYPE_EDGE);
int s_buttonFont = CreateFontToHandle("~", 20, 3, DX_FONTTYPE_NORMAL);
struct ButtonInfo
{
int x;
int y;
int z;
float radius;
//int width;
//int height;
const char* text;
bool clicked;
int fontHandle;
};
DrawGraph(s_bgX, s_bgY, s_backgroundImage, TRUE);
int mx = 0, my = 0, minput = 0, wheel = 0;
int second_img1 = LoadGraph("C:/Users/user/Desktop/source/repos/DXlib/Data/3.png");
int bgX = 0, bgY = 0;
double angle = 0.0;
ButtonInfo buttons[6];
for (int i = 0; i < 6; ++i)
{
buttons[i].radius = 80;
buttons[i].clicked = false;
buttons[i].fontHandle = s_font;
buttons[i].z = 0;
}
buttons[0].x = 150;
buttons[0].y = 220;
buttons[0].text = "~";
buttons[1].x = 325;
buttons[1].y = 220;
buttons[1].text = "~";
buttons[2].x = 500;
buttons[2].y = 220;
buttons[2].text = "~";
buttons[3].x = 150;
buttons[3].y = 350;
buttons[3].text = "~";
buttons[4].x = 325;
buttons[4].y = 350;
buttons[4].text = "~";
buttons[5].x = 500;
buttons[5].y = 350;
buttons[5].text = "~";
for (int i = 0; i < 6; ++i)
{
const ButtonInfo& button = buttons[i];
DrawOvalAA(button.x, button.y, 80, 50, 32, GetColor(67, 116, 217), 1);
DrawStringToHandle(button.x - 50, button.y - 15, button.text, GetColor(255, 255, 255), s_buttonFont);
if (CheckHitKey(KEY_INPUT_0 + i)) {
ChangeScene(static_cast<SceneType>(SCENE_THIRD + i));
}
}
DrawRotaGraph(320, 110, 0.5, angle * DX_PI / 180, second_img1, 1);
}
void ThirdScreen()
{
int C = GetColor(255, 255, 255);
int TEST;
DrawBox(270, 190, 370, 290, GetColor(255, 255, 255), TRUE);
SetKeyInputStringColor(GetColor(0, 0, 0), GetColor(0, 0, 0), C, C, C, C, C, C, C, C, C, C, C, C, C, C, C);
TEST = KeyInputNumber(270, 190, 100, 1, FALSE);
}