【问题标题】:C++ sfml how to rotate a character from its centerC ++ sfml如何从中心旋转字符
【发布时间】:2021-12-31 21:11:02
【问题描述】:

我想使用 sprite.rotate() 和 sprite.setrotation() 函数,但 sfml 考虑了精灵的右上角。如何将此点设置为精灵中心?

【问题讨论】:

  • 你有SFML manual吗?
  • 有一个名为RectangleShape 的类可以做到这一点。搜索并了解如何使用它。

标签: c++ rotation sfml


【解决方案1】:

如果你想设置旋转中心,你必须使用sprite.setOrigin()函数来设置位置和旋转的中心。

例如:

sf::Texture texture;
if (!texture.loadFromFile("texture.png"))
    exit(-1);

sf::Sprite sprite;
sprite.setOrigin((sf::Vector2f)texture.getSize() / 2.f);

或者,如果您要更改精灵的纹理矩形:

sprite.setOrigin(sf::Vector2f(sprite.getLocalBounds().width, sprite.getLocalBounds().height) / 2.f);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 2017-06-07
    • 2020-02-13
    • 1970-01-01
    • 2015-05-14
    相关资源
    最近更新 更多