SDL——关于角色移动
我想从lazyfoo.com询问SDL中的角色移动
,有一个教程解释了移动,从我读到的内容,我得出结论,这些是对象移动的步骤
- 检测到的事件
- 根据事件设置新坐标
- 使屏幕变白(SDL_FillRect())
- 然后用新坐标绘制对象 (applySurface())
我的问题是我使用的是基于 2D 图块的地图(不是白色表面),并且我在第 3 步中遇到了麻烦......如何在移动角色时维护地图?(不使屏幕变白)
如果有人可以发布代码,我将不胜感激
THX
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
- Events detected
- set new coordinates based on events
- make the screen white (SDL_FillRect())
- 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想改变玩家的位置而不需要重新绘制地图吗?
除非您的地图非常复杂,否则您应该能够每帧重新绘制它。
如果它那么复杂或者你的机器速度很慢,你可以进行以下优化:
在程序开始时将地图绘制到单独的表面。
每一帧,无需清除屏幕并重新绘制地图,只需将此表面复制到屏幕即可。复制曲面几乎与清除曲面一样快。
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.
您可以做的不是使屏幕变白,而是在主 while 循环之外使用地图进行 BlitScreen 或 FillRect,而不是每帧都执行此操作。另外,为了节省内存,您可以尝试限制 FPS。
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.