Whenever I use BlitSurface to apply a background image, the movement of my characters is slowed drastically even though I have movement based on time:

SDL_BlitSurface( background, camera, screen, offset );

Though, if I simply fill the screen with white:

SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );

The movement is exactly as I have it set.

Any idea why this could be happening?


Just a speculation: SDL_BlitSurface is lagging you down.

Test how long SDL_BlitSurface() takes; see if its significantly different from SDL_FillRect(). This will affect your character movements depending on how you implemented your game loop and physics.

  • \$\begingroup\$ I don't believe it's lagging, because my animations are running perfectly fine and are also based on time. Let me pastebin: pastebin.com/ynCkUXyB \$\endgroup\$ – Corey Jun 4 '13 at 19:27
  • \$\begingroup\$ if you are talking about lines 744-747 then your game loop is trying to blit to the screen as often as it can even if it is not drawing that frame. You should only need to blit the camera view to the screen once per draw. \$\endgroup\$ – UnderscoreZero Jun 4 '13 at 19:52
  • \$\begingroup\$ @UnderscoreZero Oh, I see. Would you mind clarifying though? What should I do as an alternative? If I take the blitting out of the gameloop, my character will leave a trail. You said "even if it not drawing that frame." But isn't it drawing the frame every loop? Maybe I'm confused about the wording. What exactly do you mean by "a draw"? \$\endgroup\$ – Corey Jun 4 '13 at 20:05
  • \$\begingroup\$ Average games draw 30-60 frames per second. So you should have a timer that says when you want to draw the frame. When it is time to draw, then you go through all the drawing steps (IE bliting stuff to the screen). If it is not time to draw, you check your other timers (like an update timer) or your event buffer. \$\endgroup\$ – UnderscoreZero Jun 4 '13 at 20:22
  • \$\begingroup\$ Gotcha, I'll give that a go. \$\endgroup\$ – Corey Jun 4 '13 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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