Best way to rotate an image using SDL?

不羁岁月 提交于 2019-12-03 16:23:24

问题


I am building a game and the main character's arm will be following the mouse cursor, so it will be rotating quite frequently. What would be the best way to rotate it?


回答1:


With SDL you have a few choices.

  1. Rotate all your sprites in advance (pre-render all possible rotations) and render them like you would any other sprite. This approach is fast, but uses more memory and more sprites. As @Nick Wiggle pointed out, RotSprite is a great tool for generating sprite transoformations.

  2. Use something like SDL_gfx to do real-time rotation/zooming. (Not recommended, very slow)

  3. Use SDL in OpenGL mode and render your sprites to primitives, applying rotation to the primitives.

Option 3 is probably your best bet because you gain all of the advantages of using OpenGL. It's really up to you how to want to do it. It's also a possibility that you can load your sprites, perform all rotation calculations with SDL_gfx and then save the rotated versions to a SDL_Surface in memory.

EDIT: In response to your comment I would recommend checking out Lazyfoo's SDL tutorals. Specifically, this one about rotation. There is also an OpenGl function, glRotatef, which can be useful in your case. A quick search brought back this little tidbit which could also be helpful.




回答2:


SDL_RenderCopyEx()

has extra arguments for rotation, flipping, and the rotation center.




回答3:


You can use a library like SDL_gfx



来源:https://stackoverflow.com/questions/1183900/best-way-to-rotate-an-image-using-sdl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!