Reputation: 452
I want to ask about character movement in SDL
from lazyfoo.com, There is a tutorial which explains about movements and from what I read, I conclude that these are the steps to object movements
My problem is that I'm using a 2D tile-based map (not a white surface) and I'm troubled at step no 3.... how to maintain the map while moving the character ??(without whitening the screen)
I'll appreciate it greatly if someone can post the codes
THX
Upvotes: 1
Views: 659
Reputation: 43
What you could do is instead of making the screen white, outside of the main while loop you BlitScreen or FillRect with your map instead of doing it every frame. Also, to save memory you could try limiting FPS.
Upvotes: 1
Reputation: 18320
You want to change position of the player without having to redraw the map?
Unless your map is really complex, you should be able to redraw it every frame.
If it is that complex or you are on slow machine, you can do the following optimization: At the beginning of the program draw the map to separate surface. Every frame, instead of clearing the screen and redrawing the map, just copy this surface to the screen. Copying surfaces is almost as fast as clearing them.
Upvotes: 1