C ++ SFML屏幕边界冲突

时间:2018-12-12 12:46:53

标签: c++ sfml

我在这里有完整代码的这段代码:

        if (player.playerSprite.getPosition().x <= 0) //Left
                player.playerSprite.setPosition(0.f, player.playerSprite.getPosition().y);

        if (player.playerSprite.getPosition().x >= window.getSize().x - player.playerSprite.getGlobalBounds().width) //Right
            player.playerSprite.setPosition(window.getSize().x - player.playerSprite.getGlobalBounds().width, player.playerSprite.getPosition().y);

        if (player.playerSprite.getPosition().y <= 0) //Top
    player.playerSprite.setPosition(player.playerSprite.getPosition().x, 0.f);

        if (player.playerSprite.getPosition().y >= window.getSize().y - player.playerSprite.getGlobalBounds().height) //Bottom
    player.playerSprite.setPosition(player.playerSprite.getPosition().x, window.getSize().y - player.playerSprite.getGlobalBounds().height);

左侧和顶部工作正常(精灵碰撞到其中但没有穿过),但精灵甚至不会靠近右侧和底部。任何想法如何解决这个问题?

0 个答案:

没有答案