Original Post
I am writing 2D game using DDraw. No 3D stuff, just typical 2D game and running under windowed mode (non-fullscreen) I wrote fullscreen game before and no problem with it. But now i am stucked: in windowed mode,I don want use typical PeekMessage gameloop because I dont want my game uses up all cpu resource. I was thinking using GetMessage,but then it will be difficult to keep constant frame updating. So, I came out this solution, hope you guys give me some advices and correct me if I am wrong: my game loop: while(1) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message==WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { if (g_bAppActive==1) { UpdateFrame(); Sleep(16); //Sleep 16 msec so it wont use up all cpu power } else { WaitMessage(); } } } Without Sleep(16),my cpu 100% consumed by this game and the system become very laggy. 16 because of 16 milliseconds and hence give resolution 60 times per second. Am I using a right concept? Oh, one more thing,UpdateFrame() is nothing but just Blitting a 800x600 background and a 71x96 moving sprite. I use time based animation,but i found sometime the sprite got shearing effect,I tried to add: pDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, NULL); before blitting primary surface,but it getting worse,it shears almost all the time,I dont know why. Really wonder how to make smooth animation under windowed mode. Thanks in advanced. regards, Martin