   Changing backgrounds?
  I'm trying to make it so when you hit a key, the background of my UFO program changes.  When you hit the key again, it changes back to the origional background.    Would you use cout and cin to do this?  I couldn't figure out how, could someone help plz thx!   
  Here's what I've got so far, but even when I press a nothing happens can someone please tell me why:  void GamePaint(HDC hDC){  // Draw the background and saucer bitmaps  g_pBackground[0]->Draw(hDC, 0, 0);  g_pSaucer[g_bSaucerFlame ? 1:0]->Draw(hDC, g_iSaucerX, g_iSaucerY, TRUE);  // Change the background when the user presses A  char input;  cin >> input;  if (input == 'A')  {g_pBackground[1]->Draw(hDC, 0, 0);  }}   ;Quote:Original post by Emper0rHere's what I've got so far, but even when I press a nothing happens can someone please tell me why:  void GamePaint(HDC hDC){  // Draw the background and saucer bitmaps  g_pBackground[0]->Draw(hDC, 0, 0);  g_pSaucer[g_bSaucerFlame ? 1:0]->Draw(hDC, g_iSaucerX, g_iSaucerY, TRUE);  // Change the background when the user presses A  char input;  cin >> input;  if (input == 'A')  {g_pBackground[1]->Draw(hDC, 0, 0);  }}AFAIK, cin will *suspend* your program until user types something. In games, you don't want to use cin. It seems you are using Win32, I suggest using GetAsyncKeyState() for simplicity's sake. Example:GetAsyncKeyState('A');One tip: Move your read input code somewhere else for cleaner code. A paint routine should only paint, not read input.   ;  When I use GetAsyncKeyState, it only changes the background when you're holding down A.I'm looking to make it so when you just press the A key on your keyboard the background will change until you press the A button again, not release it.Any idea how to do this?  Thanks a bunch for the reply.   ;  Inside your WndProc function, add a case for the WM_KEYDOWN message.  If wParam contains the virtual keycode for 'A' (which I think is literally 'A'), flip a boolean variable which indicates which background should be drawn.  Your paint method can then determine which background to render based on the value of the boolean variable.   ;  I'm very noobie, can you tell me where I can find the WndProc function?  I searched for it in the premade GameEngine.cpp that came with the example I've been altering but they were just calls, not the function itself.Thanks a bunch :)   ;Quote:Original post by Emper0rWhen I use GetAsyncKeyState, it only changes the background when you're holding down A.I'm looking to make it so when you just press the A key on your keyboard the background will change until you press the A button again, not release it.Any idea how to do this?  Thanks a bunch for the reply.You were on the right track here. Instead of using code like this:if (GetKeyState('a')) DrawOtherBackground;You need to store the state in a variable so that its decoupled from the actual input, in other words so that it remembers your "decision".bool keydown = false;bool useotherbackground = false;void GetInput(){  if (GetAsyncKeyState('A'))  {if (keydown) //skip out, we already know we're holding the key{}else //keys not down{   useotherbackground = !useotherbackground; //flip variable   keydown = true; //acknowledge that we hit the key}  }  else //the user released the key  {keydown = false;  }   }void Draw(){   if (useotherbackground)   {  DrawOtherBackground();   }   else   { DrawOriginalBackground();   }}