//这个是在主函数中添加的

//游戏循环
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
tNow = GetTickCount();
if (tNow - tPre >= 100)//相差0.1秒时再进行重绘操作
MyPaint(hdc);
}
}

 

 


//--------------------------------------------InitInstance() 函数----------------------------------------------
//加载资源
//-------------------------------------------------------------------------------------------------------------
BOOL InitInstance(HINSTANCE hInstance, int nShowCmd)
{
HWND hwnd;
char filename[20] = "";

//创建窗口第三步:正式创建窗口
//创建窗口函数
hwnd = CreateWindow("GameClass", WINDOW_TITLE, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hwnd)
{
return FALSE;
}
//创建窗口第四步:窗口的移动,显示和更新
MoveWindow(hwnd, 250, 80, WINDOW_WIDTH, WINDOW_HEIGHT, true);//调整窗口显示时的位置及窗口的大小
ShowWindow(hwnd, nShowCmd);//设定显示窗口时的状态
UpdateWindow(hwnd);//将窗口绘制于显示设备上

hdc = GetDC(hwnd);
mdc = CreateCompatibleDC(hdc);

//加载图片
for (int i = 0; i<7; i++)
{
wsprintf(filename, "man%d.bmp", i);
man[i] = (HBITMAP)LoadImage(NULL, filename, IMAGE_BITMAP, 640, 480, LR_LOADFROMFILE);
}

num = 0;
frame = 0;

MyPaint(hdc);

return TRUE;
}

//--------------------------------------------MyPaint() 函数---------------------------------------------------
//绘制图形
//-------------------------------------------------------------------------------------------------------------
void MyPaint(HDC hdc)
{
char str[40] = "";
if (num == 7)
num = 0;
frame++;
if (tNow - tCheck >= 1000)
{
fps = frame;
frame = 0;
tCheck = tNow;
}

SelectObject(mdc, man[num]);
BitBlt(hdc, 0, 0, 600, 450, mdc, 0, 0, SRCCOPY);

tPre = GetTickCount();//记录此次绘图时间
num++;
}

 

如需整体运行框架,请点击: 游戏框架

游戏开发的梦想

梦开始的地方

posted on 2015-11-22 23:34  zishen  阅读(294)  评论(0编辑  收藏  举报