【发布时间】:2021-08-14 19:33:28
【问题描述】:
我是使用 SFML 的新手,我想知道是否有人可以告诉我如何使用鼠标指针在其中心旋转对象。
例如,如果我按下right 按钮,它应该顺时针方向旋转,如果我按下left 按钮,它应该逆时针方向旋转。
【问题讨论】:
我是使用 SFML 的新手,我想知道是否有人可以告诉我如何使用鼠标指针在其中心旋转对象。
例如,如果我按下right 按钮,它应该顺时针方向旋转,如果我按下left 按钮,它应该逆时针方向旋转。
【问题讨论】:
这就是你要找的吗?如果您需要进一步解释,请写下来。
sf::RectangleShape shape;
shape.setSize({100.0f, 100.0f});
// Set origin point in the center of the object, to rotate it around the center
shape.setOrigin({shape.getSize().x / 2, shape.getSize().y / 2});
// Angle value you'll rotate the shape by
float angle = 1.0f;
// Inside the game loop
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Right)) shape.rotate(angle);
if (sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) shape.rotate(-angle);
【讨论】: