Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to write a platforming game where the sprites for the level backgrounds are broken up into 512x512 chunks. I keep 3 chunks in memory at a time and I'm trying to write code to blit all three to the screen. Here is the current code I have:

SDL_Rect where;
where.y = -game->camera->y;

where.x = -game->camera->x - MAP_WIDTH;
SDL_BlitSurface(left_chunk, NULL, screen, &where);

where.x = -game->camera->x;
SDL_BlitSurface(center_chunk, NULL, screen, &where);

where.x = -game->camera->x + MAP_WIDTH;
SDL_BlitSurface(right_chunk, NULL, screen, &where);

The issue I'm running into is that whichever chunk gets blitted first is the only one that shows up. The rest fail to appear onscreen. I think the issue might have something to do with alpha transparency, but even if the chunks don't overlap at all they still fail to blit. In other parts of the code I'm blitting multiple things to the screen at once, such as characters and backgrounds, and they all show up correctly. This particular segment of code is the only area I'm encountering this problem.

Screenshot

If I comment out the line that blits left_chunk, it changes to this:

Screenshot After

share|improve this question
    
Are you sure that your calculated X values position the image in the visible area of the screen? –  Zack The Human Oct 22 '12 at 18:07
    
@ZackTheHuman They are partially offscreen, since the screen is only 300x175 and the map chunks are 512x512. I thought that may have been the problem at first, but whether they are onscreen or not seems to be irrelevant to whether it is rendering correctly or not. I can upload a screenshot to help illustrate the problem. –  extropic-engine Oct 22 '12 at 18:10
1  
The SDL documentation says that SDL_BlitSurface saves the final rectangle to dstrect after blitting. Have you tried reseting the where variable after each blit? –  Asakeron Oct 22 '12 at 18:39
    
@Asakeron That was it! I didn't expect where to be modified. You should make your comment an answer! –  extropic-engine Oct 22 '12 at 18:42
add comment

1 Answer 1

up vote 8 down vote accepted

The SDL documentation says that SDL_BlitSurface saves the final rectangle to dstrect after blitting. Reseting the where variable fixes the problem.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.