   Animation Problem
  I am having a problem with my animations. I believe it comes down to a timer problem, so I was wondering if anybody could show me how to put a little timer into this piece of code.//Defined way before as defaultsenum ANIMATIONSTATE{UPFACING,DOWNFACING};ANIMATIONSTATE aState = DOWNFACING; case WM_KEYDOWN:  {    int xas = (int)wParam; if(xas == VK_DOWN) {  if(aState == DOWNFACING)  {   y += 1.5;   if(asprite->currentFrame > 2)   { asprite->currentFrame = 0;   }   else   {  asprite->currentFrame++;   };  }  else if(aState == UPFACING)  {   asprite->currentFrame = 0;  };  aState = DOWNFACING; } if(xas == VK_UP) {  if(aState == UPFACING)  {   y -= 1.5;   if(asprite->currentFrame > 6)   { asprite->currentFrame = 5;   }   else   {  asprite->currentFrame++;   };  }  else if(aState == DOWNFACING)  {   asprite->currentFrame = 5;  };  aState = UPFACING;};If my explanation of the problem was a bit unclear, what I'm simply saying is that my animation is jerky, like you can probably see in this video:">Click here to see the videoAnd I believe its a timer problem, so I'm simply asking for someone to show me how to regulate the animation time between when the player moves. Thanks in advance.   
  Heh, I just coded something for this a few days ago.I see quite a few things wrong here:1. To make life easier for yourself you probably want those UPFACING/DOWNFACING states passed to the sprite before or during its update phase rather than setting them directly in your input handler. This allows you to simply check input and set the state. No other fuss. Within the sprite mechanism itself it should be handling the details of what, when, and how to change frames of animation.2. It looks like the messages sent aren't coming in at regular intervals (it's been such a long time since I've used windows messages I don't exactly remember how it all works for input). As stated above, having the animation logic within the message handler will cause trouble. The animation is only processed when the input comes through the pump. You want your sprite updating itself every single frame of the main game loop (or at least every frame that is rendered during the game loop). So break up these two sections, while your at it, refactor that movement logic too.3. I'm lazy so I'm just going to give you a link to a recent post where I described how my animation worked with timers. Check my second post for a better explanation. If you still need with details, just ask ;)Timers Thread