   Frame Rate problem with SDL
  Ive been programming with SDL for a short while, and i am currently trying to make a scrolling shooter. Everything is lookin pretty good so far, except for the fact that when i go to run the program, it doesnt move. As soon as i enter some kind of input, (i.e. moving the character, making it shoot) it will move a frame, and it will stop, until i press another key. I also noticed that while i move around the mouse within the window, the program runs smoothly, but as soon as i stop the movement with the mouse, the frame will freeze, until further input. I am working on this at school, and it may be a problem with the school computers, im not sure. Im using Dev C++ with all the latest SDL libraries... i dont know what the problem could be... Any help would be GREATLY appreciated.   
  Post your input code   ;  heh, its pretty long...some of it is modified code from one of the SDL tutorials on cone3d.newayz here it is..(My apologies for not using source tags, didnt know about them, im new here ^_^)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#include <stdio.h>#include <stdlib.h>#include <time.h>#include <math.h>#include <SDL/SDL.h>#include "CSprite.h"#include "CSpriteBase.h"#include "font.h"#define BLAST 10#define ENEMIES 10int td=0,td2=0;    float dt=0;   float sdlgt=0; SDL_Surface *screen, *back, *logo, *smallgoku, *gameoverimg;SDLFont *font,*yellowfont;CSpriteBase gokubase;CSprite goku;CSpriteBase blastbase;  CSprite blast[BLAST]; int bdraw[BLAST];CSpriteBase enemybase;    CSprite enemies[ENEMIES]; int edraw[ENEMIES];  int espeed[ENEMIES]; int elife[ENEMIES];  int einfo[ENEMIES];  int paused=0;   int gameover=0; float scroll=0; Uint32 elast;   Uint32 dtime;   int score=0,lives=5; short int Sprite_Collide(CSprite &object1, CSprite &object2){  // We store the coordinates of our reduced rectangles here  double left1, left2;  double right1, right2;  double top1, top2;  double bottom1, bottom2;  left1 =   object1.getx()+object1.getw()*0.1;  left2 =   object2.getx()+object2.getw()*0.1;  top1 =    object1.gety()+object1.geth()*0.1;  top2 =    object2.gety()+object2.geth()*0.1;  right1 =  object1.getx()+object1.getw()*0.9;  right2 =  object2.getx()+object2.getw()*0.9;  bottom1 = object1.gety()+object1.geth()*0.9;  bottom2 = object2.gety()+object2.geth()*0.9;  // We now do some little comparing and return 0 if the rectangles  // aren't colliding and 1 if they are.  if (bottom1 < top2) return 0;  if (top1 > bottom2) return 0;  if (right1 < left2) return 0;  if (left1 > right2) return 0;  return 1;};SDL_Surface * ImageLoad(char *file){  SDL_Surface *temp1, *temp2;  temp1 = SDL_LoadBMP(file);  temp2 = SDL_DisplayFormat(temp1);  SDL_FreeSurface(temp1);  return temp2;}void DrawIMG(SDL_Surface *img, int x, int y){  SDL_Rect dest;  dest.x = x;  dest.y = y;  SDL_BlitSurface(img, NULL, screen, &dest);}void DrawIMG(SDL_Surface *img, int x, int y,    int w, int h, int x2, int y2){  SDL_Rect dest;  dest.x = x;  dest.y = y;  SDL_Rect dest2;  dest2.x = x2;  dest2.y = y2;  dest2.w = w;  dest2.h = h;  SDL_BlitSurface(img, &dest2, screen, &dest);}void DrawScroll(){  if(scroll>3909-3500)  {    DrawIMG(back, 0,60,(int)(3909-scroll),400,(int)scroll,0);    DrawIMG(back, (int)(3909-scroll-1),60,  (int)(640-(3909-scroll)),400,0,0);    } else {    DrawIMG(back, 0,60,640,400,(int)scroll,0);  }}void addBlast(){  for(int i=0;i<BLAST;i++)  {    if(bdraw==0)    { blast.set(goku.getx()+70,goku.gety()+23); bdraw=1; return;    }  }}void addEnemy(){  for(int i=0;i<ENEMIES;i++)  {    if(edraw==0)    {   enemies.setFrame(0);   einfo=0; } enemies.stopAnim(); enemies.set(640,60+rand()%350); espeed=rand()%4+1; elife=rand()%3+1; edraw=1; return;    }  }void DrawScene(){  SDL_FillRect(screen,0,0);  DrawScroll();  DrawIMG(logo, 0, 0);  if(lives>0)  {    for(int i=0;i<lives;i++)    { DrawIMG(smallgoku,605-i*30,28);    }  }  for(int i=0;i<BLAST;i++)  {    if(bdraw==1) {blast.draw();}  }  for(int i=0;i<ENEMIES;i++)  {    if(edraw==1) {enemies.draw();}  }  goku.draw();  if(gameover)  {    DrawIMG(gameoverimg, 192, 200);  }  SDL_Flip(screen);}using namespace std;int main(int argc, char *argv[]){  srand(time(NULL));  Uint8* keys;    if(SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0)  {    printf("Unable to init SDL: %s\n", SDL_GetError());    exit(1);  }  atexit(SDL_Quit);screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE|SDL_DOUBLEBUF);  if ( screen == NULL )  {    printf("Unable to set 640x480 video: %s\n", SDL_GetError());    exit(1);  }  back = ImageLoad("data/repeat.bmp");  logo = ImageLoad("data/logo.bmp");  smallgoku = ImageLoad("data/smallgoku.bmp");  gameoverimg = SDL_LoadBMP("data/gameover.bmp");    SDL_SetColorKey(gameoverimg, SDL_SRCCOLORKEY,    SDL_MapRGB(gameoverimg->format, 0, 255, 0));gokubase.init("data/ship");  blastbase.init("data/blast");  enemybase.init("data/enemy");  for(int i=0;i<BLAST;i++)  {    blast.init(&blastbase,screen);  }  for(int i=0;i<ENEMIES;i++)  {    enemies.init(&enemybase,screen);  }  goku.init(&gokubase,screen);  goku.set(50,220);  goku.setSpeed(1);  SDL_ShowCursor(0);    font = initFont("data/font");  yellowfont = initFont("data/font",1,1,0);  int done=0;  while(done == 0)  {td2=SDL_GetTicks();    dt=((float)(td2-td))*0.1;    td=td2;if(!paused)    { sdlgt+=dt*10;    }    SDL_Event event;    while(SDL_PollEvent(&event))    { if(event.type == SDL_QUIT) { done = 1; } if(event.type == SDL_KEYDOWN) {   if(event.key.keysym.sym == SDLK_ESCAPE)   {done = 1;   }   if(event.key.keysym.sym == SDLK_SPACE && !paused && !gameover)   {addBlast();if(event.key.keysym.sym == SDLK_p)   {paused=!paused;   }   if(event.key.keysym.sym == SDLK_RETURN && gameover)   {for(int i=0;i<ENEMIES;i++) edraw=0;for(int i=0;i<BLAST;i++) bdraw=0;goku.set(50,220);goku.setSpeed(1);goku.setFrame(0);goku.startAnim();gameover=0;lives=5;score=0;dtime=(Uint32)sdlgt;   } }    }    keys = SDL_GetKeyState(NULL);    if(!paused && !gameover)    { if(keys[SDLK_UP]) {   goku.yadd((int)(-2*dt));   if(goku.gety()<60) goku.yset(60); } if(keys[SDLK_DOWN]) {   goku.yadd((int)(2*dt));   if(goku.gety()>410) goku.yset(410); } if(keys[SDLK_LEFT]) {   goku.xadd((int)(-2*dt));   if(goku.getx()<0) goku.xset(0); } if(keys[SDLK_RIGHT]) {   goku.xadd((int)(2*dt));   if(goku.getx()>570) goku.xset(570); }    }if(!paused && !gameover)    { for(int i=0;i<BLAST;i++) {   if(bdraw==1)   {blast.xadd(3.5*dt);  if(blast.getx()>640){bdraw=0;}   } } for(int i=0;i<ENEMIES;i++) {if(edraw==1)   {enemies.xadd(-((float)espeed+1)*dt*0.5); } if(enemies.getx()<-50){edraw=0;continue;}    }}if(sdlgt-dtime>3000) {   goku.stopAnim();   goku.setSpeed(0); goku.setFrame(0); } scroll += dt; if(scroll>=3909) scroll-=3909;    }    DrawScene();    SDL_Delay(1);  }   return 0; }[\source] [Edited by - stylz on November 18, 2005 11:28:17 AM];  AH! Use the source tags!   ;  I have a tutorial on how to make stuff move around on the screen properly*points to sig*It's tutorial 12.   ;  at first glance, you should check all your curly braces, they seem to be pretty messed up...second: you have the while loop for input before actually calling DrawScene(). so the prog will loop until you press a button, process the input and then draw your scene to the screen. put the DrawScreen()-call into the outermost input-loop and it should work.   ;  Hmm, my braces seem to be fine, I guess I just have bad programming structure, lol...But I dont quite get what you mean about the drawscene...   ;  He means that he solved the problem.Your program is waiting until you input something BEFORE drawing things.It should be able to draw things without requiring input   ;  so where do i put drawScene()?ive tried everywhere and nothing works...   ;  I'm going to bump this because I still haven't solved my problem :(I'm going to include a link to the zip of my project:[link]http://s58.yousendit.com/d.aspx?id=0UUFUB2DVLNJL2TS35P97XRVU4[\link]The problem im having is the screen stops moving until I move the mouse around in the window, or press keys, as soon as I stop, the animation will also stop.I dont see what the problem is, I compared it to a tutorial at cone3d and I seem to be doing everything ok. Maybe someone can point out what im doing wrong. Any help would be greatly appreciated.   