以下のようなコードでは変数「count」がちゃんと1ループごとに増えていきます。
(class内の関数であれば値が保持されることを確認するためにDraw関数にもcountの値を表示させています)
//main.cpp
#include "DxLib.h"
#include "test.h"
C_Test Test;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
{
ChangeWindowMode(TRUE);
if(DxLib_Init() == -1) return -1;
if(SetDrawScreen(DX_SCREEN_BACK) != 0) return -1;
}
//メインループ(ESCで終了)
while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0)
{
//画面の初期化
ClearDrawScreen();
Test.Count();
Test.Draw();
//フリップ
ScreenFlip();
}
DxLib_End();
return 0;
}
//test.cpp
#include "test.h"
void C_Test::Count()
{
count++;
DrawFormatString(0,0,GetColor(255,0,0),"%d",count);
}
void C_Test::Draw()
{
DrawFormatString(0,20,GetColor(255,0,0),"%d",count);
}