How to rotate a rect in SDL2?

一世执手 提交于 2019-12-10 14:53:32

问题


I plan on making a game, and I want to create some background animations for said game. One of these animations is a rotating rectangle. I've looked all over, and I cannot find any form of math or logic that allows me to rotate a rectangle (SDL_Rect to be specific, but you might have already known that).

I can't figure out the math for myself, I really don't have any working code for this, so I can't show anything.

Essentially I'm looking for some type of logic that I can apply the rectangle's coordinates so that whenever the main game loop loops, it will rotate the rectangle some amount of degrees.


回答1:


You can't rotate an SDL_Rect. If you look at its definition, it's made of coordinates for the top-left corner, the width and the height. There's no way to represent a rectangle with sides that aren't parallel to the coordinate system's axes.

SDL_RenderCopyEx supports drawing rotated textures, though.



来源:https://stackoverflow.com/questions/30198713/how-to-rotate-a-rect-in-sdl2

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