Well. My problem is really really confusing and I don't get it really. Basically, I have a little thing that I paint to the screen, and move it around with the arrow keys. When I, for example, am notified that the right arrow key is pressed, I get a WM_KEYDOWN, and I start a timer which slowly increments to speed of the object, accelerating it. When I get the WM_KEYUP of the right arrow key, I kill the timer. Here is how it is implemented. Scroll to the bottom for description of my problem.
Okay. So, I output the speed of my object, and here's how the debug output looks, with commenting on what I'm doing.Code:case WM_KEYDOWN: try { Thingy & t = s.find(ID_CIRCLE); switch(wParam) { case VK_RIGHT: if(!::SetTimer(hwnd, ID_RIGHTARROW, 100, NULL)) { ErrorMessage(_T("%d"), ::GetLastError()); } break; case VK_LEFT: ::SetTimer(hwnd, ID_LEFTARROW, 100, NULL); break; } t.move(); s.update(); ::InvalidateRect(hwnd, NULL, TRUE); } catch(std::exception & e) { ErrorMessage(_T("Error: %d"), e.what()); } break; case WM_KEYUP: switch(wParam) { case VK_RIGHT: ::KillTimer(hwnd, ID_RIGHTARROW); break; case VK_LEFT: ::KillTimer(hwnd, ID_LEFTARROW); break; } break; case WM_TIMER: try { Thingy & t = s.find(ID_CIRCLE); switch(wParam) { case ID_RIGHTARROW: t.setSpeed(t.getXSpeed() + 1, t.getYSpeed()); break; case ID_LEFTARROW: t.setSpeed(t.getXSpeed() - 1, t.getYSpeed()); break; } TCHAR buf[256]; wsprintf(buf, _T("%d\n"), t.getXSpeed()); ::OutputDebugString(buf); } catch(std::exception & e) { ErrorMessage(_T("Error: %d"), e.what()); } break;
I figured out I get multiple WM_KEYDOWN messages while I'm holding it, and figured SetTimer would be failing, but it isn't. I can't tell what's going on with this, it's really illogical.Code:-1 // I press VK_LEFT, and hold it for awhile. -2 -3 -4 // Still holding VK_LEFT, it stops accelerating to a greater but still moves. I let go of VK_LEFT and press VK_RIGHT -3 -2 -1 0 // Decelerates until 0, then stops decelerating. Again, even as I'm holding VK_RIGHT. I keyup, and press VK_RIGHT again. 1 2 3 4 // It accelerates up 4 more, and stops. I keyup, and press VK_RIGHT again. 5 6 7 8 // 4 more. Stops. You get the idea.



LinkBack URL
About LinkBacks


