开发者

SDL - about character movement

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

  1. Events detected
  2. set new coordinates based on events
  3. make the screen white (SDL_FillRec开发者_StackOverflow社区t())
  4. Then draw the object with new coords (applySurface())

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜