关于SDL的一些问题
我正在使用 SDL 开始一个小型 RTS 游戏,这里有一些问题:
- 我使用小精灵,是 有一种显示屏幕的方法 x2 带扫描线? 我尝试缩放 它与 rotozoom 但速度减慢 游戏,我想避免手动缩放我的精灵。
- 我怎样才能切换 在全屏和窗口之间 跑步 ? 我找到了
SDL_WM_ToggleFullScreen
功能但是 它似乎不适用于 Windows 根据 SDL 文档。 - 为了放置我自己的光标,我用指针加载一个精灵并 让它跟随鼠标。 但我会 也喜欢降低帧率
SDL_Delay
这样做使得 指针移动不顺畅。 SDL 光标似乎不受 应用程序帧速率是 更好的解决方案来使用它,如果是这样,有没有办法使用图片而不是奇怪的面具? - 有没有更好的方法来限制帧率?
- 如何为表面着色(例如使用
draw_lit_sprite
中的 快板)
I'm starting a little RTS game with SDL and here are some questions:
- I work with small sprites, is
there a way of displaying the screen
x2 with scanlines ? I tried zooming
it with rotozoom but it slows down
the game and I would like to avoid scaling my sprites by hand. - How can I switch
between fullscreen and windowed while
running ? I found theSDL_WM_ToggleFullScreen
function but
it doesn't seems to work on Windows
according to SDL doc. - In order to put my own cursor I load a sprite with my pointer and
make it follow the mouse. But I would
also like to lower the framerate withSDL_Delay
and doing so makes the
pointer movements not smooth. The SDL
cursor doesn't seemed influenced by
the application framerate is it a
better solution to use it and if so, is there a way of using a picture instead of a weird mask ? - Is there a better way of limiting framerate ?
- How can I tinte a surface (like with
draw_lit_sprite
in
Allegro)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,文档指出
SDL_WM_ToggleFullScreen
函数当前仅适用于 X。我的做法如下:
对于以下几点:
我几乎会建议将 OpenGL 模式与 SDL 结合使用。 它将为您提供硬件加速的自由来执行此类操作。
rotozoom
都是在软件中完成的(据我所知),这就是它如此慢的原因。 总是会很慢。以 2x 绘制精灵时,您可能有的另一种选择是将所有内容绘制到 1x 大小的纹理,然后在绘制所有内容后,将该纹理缩放 2x。 那么您只需处理单个表面,而不是每帧一遍又一遍地处理许多小表面。
至于光标问题,听起来您可能希望尽快绘制,但仅以恒定速率更新您的游戏。 这样你就可以流畅地滚动,但游戏不会失控。
Yes, the documentation states that the
SDL_WM_ToggleFullScreen
function currently only works for X.The way I do it is like so:
For these points:
I would almost recommend using OpenGL mode with SDL. It will give you hardware-accelerated freedom to do these kinds of things.
rotozoom
is all done in software (to my knowledge) and that's why it's so slow. It'll always be slow.One other option you might have with drawing the sprites at 2x is to draw everything to a 1x sized texture, and then after everything is drawn, scale that texture 2x. Then you're only processing a single surface rather than many small ones over and over per frame.
As for the cursor issue, it sounds like you may want to be drawing as fast as possible, but only updating your game at a constant rate. That way you will have smooth scrolling but the game play won't get out of control.
Sprite 大小 - 对于任何类型的实时缩放或旋转,您最好使用 OpenGL,而不是像 SDL 这样的软件 blitter。 其他库,例如 SFML 为您解决了这个问题。
全屏/窗口 - Zack 的答案看起来足够好,只需再次调用 SDL_SetVideoMode 即可。
光标移动 - 通常操作系统将鼠标与底层应用程序分开呈现,以使其保持响应。 如果您自己渲染鼠标光标,那么您唯一的办法就是更快地渲染游戏。 我认为您对光标本身没有太多选择(可能是由于跨平台要求)。
帧速率 - 许多人建议将游戏中的运动和物理与帧速率解耦(例如,请参阅“修正你的时间步长')。 另外,请注意,SDL_Delay 对等待时间施加了下限,而不是上限。
对表面着色 - 同样,这最好由 OpenGL 执行,因为 SDL 不直接支持此操作。
Sprite size - for any sort of real-time scaling or rotation you're best off with OpenGL rather than a software blitter like SDL. Other libraries such as SFML wrap this up for you.
Fullscreen/Windowed - Zack's answer looks good enough, just call SDL_SetVideoMode again.
Cursor movement - Usually the OS renders the mouse separately from the underlying application so that it stays responsive. If you're rendering the mouse cursor yourself then your only recourse is to render your game more quickly. I don't think you get much choice over the cursor itself though (possibly due to cross-platform requirements).
Framerate - many suggest decoupling in-game movement and physics from your framerate (eg. see 'Fix Your Timestep'). Also, be aware that SDL_Delay imposes a lower bound on the waiting time, not an upper bound.
Tinting a surface - again, this is best performed by OpenGL since SDL doesn't support this directly.