Jump to content
  • Advertisement
Sign in to follow this  
DominicHughes

SDL and Rectangle movement not moving ?

This topic is 2528 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I'm building a game and I want the background to keep moving too the left here is a video showcasing the problem

http://www.youtube.c...z0KsSWtcA#t=56s

but the backgrond will not continue left but bounce off and keep repeating as you can clearly see in the video

here is the code causing the problem I spent all day tweaking this code with no luck what so ever



int LevelOneFunction(void *unused)
{
SDL_Rect MainRect;
SDL_Rect LevelOneRect;
SDL_Rect GroundOneRect;
SDL_Rect MarioRect;
MainRect.x = 10;
MainRect.y = 0;
MarioRect.x = 0;
MarioRect.y = 280;

LevelOneRect.x = -10;
LevelOneRect.y = 0;
GroundOneRect.x = 0;
GroundOneRect.y = 0;

SDL_FillRect(Screen,NULL,(0,0,0));

SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);

SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
SDL_Flip(Screen);

//On and Off Level One Switch
bool done = false;

//Event Creation
SDL_Event event;
//While Done is equal false
while(!done)
{
//While continous events are running in event
while(SDL_PollEvent(&event))
{
//allow to be able to switch events
switch(event.type)
{
//if user presses on close
case SDL_QUIT:
//Close Application
return 0;

//break case
break;

//While Any Key is Down
case SDL_KEYDOWN:
//Allow Keyboard Events
switch(event.key.keysym.sym)
{
//Up is Pressed
case SDLK_RIGHT:

LevelOneRect.x +=6;
GroundOneRect.x +=2;
MarioRect.x+=8;
//First Frame
SDL_FillRect(Screen,NULL,(0,0,0));
MainRect = LevelOneRect ;
SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);
MainRect = GroundOneRect ;
SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
MainRect = MarioRect ;
SDL_BlitSurface(SuperMarioWalk1Surf,NULL,Screen,&MarioRect);
SDL_Flip(Screen);

/////////////////////////////////////////
//Second Frame
SDL_FillRect(Screen,NULL,(0,0,0));
MainRect = LevelOneRect;
SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);
MainRect = GroundOneRect;
SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
MainRect = MarioRect;
SDL_BlitSurface(SuperMarioWalk2Surf,NULL,Screen,&MarioRect);
SDL_Flip(Screen);

/////////////////////////////////////////

//Third Frame
SDL_FillRect(Screen,NULL,(0,0,0));
MainRect = LevelOneRect;
SDL_BlitSurface(LevelOneBG,NULL,Screen,&LevelOneRect);
MainRect = GroundOneRect;
SDL_BlitSurface(GroundOneBG,NULL,Screen,&GroundOneRect);
MainRect = MarioRect;
SDL_BlitSurface(SuperMarioWalk3Surf,NULL,Screen,&MarioRect);
SDL_Flip(Screen);

/////////////////////////////////////////

break;

}
break;
}

}

}

}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!