本文介绍了如何在 SDL2 中旋转矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算制作一款游戏,我想为该游戏制作一些背景动画.这些动画之一是旋转矩形.我已经翻遍了所有内容,但找不到任何形式的数学或逻辑可以让我旋转矩形(具体来说是 SDL_Rect,但您可能已经知道).

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.

推荐答案

你不能旋转 SDL_Rect.如果你看看它的定义,它是由左上角、宽度和高度的坐标组成的.无法表示边不平行于坐标系轴的矩形.

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 支持绘制旋转纹理.

SDL_RenderCopyEx supports drawing rotated textures, though.

这篇关于如何在 SDL2 中旋转矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 08:44