[SDL] Mac SDL queries

Mike Powell belar at earthling.net
Wed Apr 26 19:12:24 PDT 2000


Hello,
	I've just started to play around with the SDL, and I put together my first
demo app last night. Now that I've gotten into it, the SDL is proving to be
a very effective and simple library to use, much thanks go to the
developers.
Something strange is occurring in my simple app that I noticed last night,
the app launches loads two images which fills an array of four faces (one
image for even one for odd), then it begins to move the images around the
screen bouncing them off walls and cycling through the faces 0-3. This all
works fine, the problem is that when I set the displacement of the surface
to 20 pixels the old image isn't fully cleared before the new image is
drawn, but when the displacement is 10 pixels no artifacts are left behind.
Now I assume that if artifacts are begin left at 20 pixels they should be
there at 10 pixels as well, right? I'll include the main event loop so you
can see what I'm doing in moving the sprite (this loop is not at all done
well, but it works for my purpose of demoing SDL):


  while(1){

    objects->pos.w = objects->faces[objects->cur_face].rect.w;
    objects->pos.h = objects->faces[objects->cur_face].rect.h;

    if((objects->pos.x + objects->vx) < 0 ||
       (objects->pos.x  + objects->pos.w ) > 640){
      objects->vx = -objects->vx;
    }
    if((objects->pos.y + objects->vy) < 0 ||
       (objects->pos.y  + objects->pos.h ) > 480){
      objects->vy = -objects->vy;
    }
    objects->pos.x += objects->vx;
    objects->pos.y += objects->vy;

    SDL_BlitSurface(objects->faces[objects->cur_face].face,
		    NULL,
		    screen,
		    &(objects->pos));
     SDL_UpdateRects(screen,1,&(objects->pos));

     if(objects->cur_face < (SAMP_SPRITE_MAX_FACE-1))
       objects->cur_face++;
     else
       objects->cur_face=0;

     fprintf(stderr,"pos: x: %d y: %d w: %d h: %d\n cur_face: %d\n vx: %d
vy: %d\n",objects->pos.x,objects->pos.y,objects->pos.w,
objects->pos.h,objects->cur_face,objects->vx,objects->vy);

     if(SDL_PollEvent(&the_event)){
       fprintf(stderr,"Event!!!\n");
       if(the_event.type == SDL_KEYDOWN){
	 fprintf(stderr,"\nGot a keydown\n");
	break;
      }
    }

  }

Any help would truly be appreciated. Sam & crew keep up the good work, I
like what I see. I'm sure I'll have even more questions as I get deeper into
the lib.
Thanks,
Chris Heller




More information about the SDL mailing list