Thread: SDL project leaves trail

  1. #1
    Shadow12345
    Guest

    SDL project leaves trail

    I have a sdl project. It is very fun. It doesn't work. The picture leaves a trail. Here is my Main(). I am leaving out the function prototypes to conserve space.

    Code:
    int main(int argc, char * argv[]) {
    	
    char keyCode;
    	Uint8 *keys;
    	keys = SDL_GetKeyState(NULL);
    	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) {
    		printf("Cannot initialize Audio and/or Video%\n", SDL_GetError());
    		exit(1);
    	}
    	atexit(SDL_Quit);
    	screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF|SDL_HWSURFACE); //HWwhat?
    	if(screen == NULL) {
    		printf("Unable to set 640 by 480 resolution%\n", SDL_GetError());
    		exit(1);
    	}
    
    	InitImages();
    	DrawBG();
    
    	bool done = false;
    	int xslope = 2;
    	int yslope = 2;
    
    	int speed = 1; 
    	while(done == false) 
    	{{{{{
    		
    		if( kbhit() ) {
    			keyCode = getch();
    			if(keyCode = 27) 
    				exit(1);
    		}
    		//90 degree counter clockwise: (x,y) -> (-y, x)
    		//90 degree clockwise: (x, y) -> (y, -x)
    		
    		int xopp = xslope * 2;
    		int yopp = yslope * 2;
    
    		//for vertical movement need to turn yslope into opposite reciprocal
    		//(speed % 5 == 0)? (xpos = (xslope += (speed / 5))): xpos + xslope;
    		//(speed % 5 == 0)? (ypos = (yslope += (speed / 5))): ypos + yslope;
    		//xpos += (speed % 5 == 0)? (xslope + (speed / 5)) : xslope;
    		//ypos += (speed % 5 == 0)? (yslope + (speed / 5)) : yslope;
    	
    		ypos += yslope;
    		xpos +=xslope;
    		
    		if(ypos < 0) { 
    			ypos = 0;
    			yslope = ( yslope - yopp );
    			yslope < 0? yslope-- : yslope++;
    		}
    	
    		if(ypos >= (480 - 66)) { 
    			ypos = (480 - 66);
    			yslope = ( yslope - yopp );
    			yslope < 0? xslope-- : xslope++;
    		}
    
    		if(xpos < 0) { 
    			xpos = 0;
    			xslope = ( xslope - xopp );
    			xslope < 0? xslope-- : xslope++;
    			
    		}
    
    		if(xpos >= 581) {
    			xpos = 581;
    			xslope = (xslope - xopp );
    			xslope < 0? xslope-- : xslope++;			
    			
    		}
    		
    
    		DrawScene();
    
    	}}}}}
    
    		return 0;
    }
    seriously though, if you can see anything wrong PLEASE tell me.
    I will be greatly indebted

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    You are way more advanced than me but no one will be able to completely help you if you do not include the whole source.
    What is C++?

  3. #3
    Shadow12345
    Guest
    anyone who knows SDL only needs to see this source.

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    SDL != Easy for me...

    I dont understand it...
    But im sure Prelude or Bubba would help...
    What is C++?

  5. #5
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    I'd need to see your DrawScene() code but my guess is that you're not clearing the screen each frame.

    - SDL_HWSURFACE tells SDL to create the surface in video memory rather than system memory.
    Last edited by taylorguitarman; 05-25-2002 at 10:31 PM.
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

  6. #6
    Shadow12345
    Guest
    Code:
    void DrawScene() {
    	Slock(screen);
    	DrawIMG(background, xpos - 2, ypos - 2, 63, 70, xpos - 2, ypos - 2); 
    	DrawIMG(ball, xpos, ypos);
    	SDL_Flip(screen); //switches the buffer 
    	Sulock(screen);
    }
    Now I thought the SDL_Flip function refreshed the screen so that this wouldn't happen.

  7. #7
    Shadow12345
    Guest
    Now I think I should clear something up. When the ball is moving at a constant speed it doesn't leave the trail. But I want it so that whenever it hits the out boundries it speeds up. This i what is causing the trail.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. SDL project won't compile (no code yet)
    By Shadow12345 in forum Game Programming
    Replies: 7
    Last Post: 05-25-2002, 12:00 PM
  4. SDL project won't compile (no code yet)
    By Shadow12345 in forum C++ Programming
    Replies: 4
    Last Post: 05-22-2002, 01:04 PM