Henning,
Try incrementing the Y or X variable of the image rect. Like so:
SDL_Rect backgroundLocation;
pictureLocation.x = 0;
pictureLocation.w = 1024; //this is the width
pictureLocation.h = 768; //this is the height
//blit your background here…
pictureLocation.y = scrollPosition;
scrollPosition–;
SDL_BlitSurface (background, &pictureLocation, screen, NULL);
//Try this for a faster scroll:
pictureLocation.y = scrollPosition;
scrollPosition -= 5;
SDL_BlitSurface (background, &pictureLocation, screen, NULL);
This has given me a wonderfully smooth and controllable scrolling
effect.
Cheers,
MaxOn Wednesday, September 3, 2003, at 02:40 PM, Henning wrote:
Hello,
I’m new to SDL and experimenting with it by trying to write some
simple game. It seems my problem has been brought up before, but I
haven’t read anything that solved my problem. Problem is how to scroll
smoothly.
I have a large background image that I scroll on a 640x480 screen
surface. I init the screen with:
screen=SDL_SetVideoMode(640,480,24,SDL_HWSURFACE|SDL_FULLSCREEN);
I move the picture by:
SDL_Rect dest;
SDL_Rect src;
src.w=640;
src.h=400;
dest.x=0;
dest.y=0;
src.x=player->x+1024;
src.y=player->y+768;
SDL_BlitSurface(levelbg, &src, screen, &dest);
SDL_Flip(screen);
(where something updates the x and y coordinates)
The image moves allright, but not smoothly. I guess it does what
people calls “tearing”. I have tried with a SWSURFACE and a HWSURFACE,
but it’s pretty much the same result (with or without doublebuffer). I
have a geforce4 card, and I have installed the nvidia driver for linux
redhat9, and it seems to be working allright (other games run
smoothly after I installed the driver). I do not know really how to
tell SDL to use the nvidia driver, if it does not do it by default. I
have also tried the “dga” driver, since someone said it was the only
one supporting double buffering with vertical sync (which seems to be
the problem), but SDL exited because it could not find the driver… I
think.
What I want to know is, if there’s no way to get smooth scrolling with
a SWSURFACE? By syncing with vertival screen updates or something. Or
else, how I get to use the HWSURFACE correctly.
It must be possible to get smooth scrolling somehow… I played some
SDL games for linux that does it fine enough.
Regards
Henning
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: text/enriched
Size: 2810 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030903/a18507db/attachment.bin