【问题标题】:How can I rotate a square shaped object using Mouse pointer in sfml?如何在 sfml 中使用鼠标指针旋转方形对象?
【发布时间】:2021-08-14 19:33:28
【问题描述】:

我是使用 SFML 的新手,我想知道是否有人可以告诉我如何使用鼠标指针在其中心旋转对象。

例如,如果我按下right 按钮,它应该顺时针方向旋转,如果我按下left 按钮,它应该逆时针方向旋转。

【问题讨论】:

    标签: c++ graphics sfml


    【解决方案1】:

    这就是你要找的吗?如果您需要进一步解释,请写下来。

    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);
    

    【讨论】:

    • 我做了同样的事情......对不起,我应该在问题中编写代码。但是发生的情况是它只选择一个命令,无论是右键还是左键。
    • 不应该是这样吗?你不能同时在两个方向上旋转一个东西。
    • 我再次检查了我的代码,我犯了一些愚蠢的错误。现在工作正常。谢谢。
    猜你喜欢
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多