version3
主要内容:封装MyBitMap
所属部分:客户端
代码地址 https://github.com/changjixiong/MMO-RPGGame, 如何获得代码,请参考如何用SVN从github上检出代码的不同版本
邮件地址:changjixiong@gmail.com
本系列目录
MyBitMap将上一篇的的贴图操作封装起来,这样更方便使用
在MyBitMap的构造函数用根据窗口的HDC 和 位图的路径,初始化成员变量bitmap,hdcBitMap等,用函数Show在指定的HDC上贴图
然后,上文中的代码就成了这个样子
HDC hdcScreen = GetDC(hwnd);
MyBitMap bitGround(hdcScreen, "./pic/map/ground.BMP");
MyBitMap bitMan(hdcScreen, "./pic/man/c00000.bmp");
// enter main event loop, but this time we use PeekMessage()
// instead of GetMessage() to retrieve messages
while(TRUE)
{
// test if there is a message in queue, if so get it
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
// test if this is a quit
if (msg.message == WM_QUIT)
break;
// translate any accelerator keys
TranslateMessage(&msg);
// send the message to the window proc
DispatchMessage(&msg);
} // end if
// main game processing goes here
// Game_Main(); // or whatever your loop is called
//BitBlt(hdcScreen, 0, 0, 640, 480, hdcGround, 0, 0, SRCCOPY);
bitGround.Show(hdcScreen);
bitMan.Show(hdcScreen);
//
} // end while
//Game_Shutdown();
但是,运行后看到,地图看的到,人物看不到(其实是闪的很快),其实是因为这个while循环太快了。