getGlobalBounds和头文件的错误

时间:2019-01-02 11:27:19

标签: c++ sfml

我正在建立自己的游戏,却被撞车卡住了。我尝试使用getGlobalBounds,但是在检查名为ice的类是否与名为Player的类冲突时出现了很多错误。

我尝试将其放入头文件中,而不是放入while(window isOpen())循环中,我现在不知道该怎么办。

class ice {
    public:

        ice(std::string imgDirectory) {
            if (!iceTexture.loadFromFile(imgDirectory)) {
                std::cerr << "Error\n";
            }
            iceSprite.setTexture(iceTexture);
            //iceSprite.rotate(180);
            iceSprite.setPosition(138,110);
        }

        void movePlayer(char direction, float moveSpeedIce) {
            if (direction == 'D') {
                iceSprite.move(0,moveSpeedIce);
            }
        }

        void drawIce(sf::RenderWindow &window) {
            window.draw(iceSprite);
        }


    private:

        sf::Texture iceTexture;
        sf::Sprite iceSprite;
};

class Player {
    public:
        Player() {
        }

        Player(std::string imgDirectory) {
            if (!playerTexture.loadFromFile(imgDirectory)) {
                std::cerr << "Error\n";
            }
            playerSprite.setTexture(playerTexture);
        //  playerSprite.scale(sf::Vector2f(0.5, 0.5));
            playerSprite.setPosition(900,760);
        }

        void drawPlayer(sf::RenderWindow &window) {
            enter code herewindow.draw(playerSprite);
        }

        void movePlayer(char direction, float moveSpeed) {
            if (direction == 'L') {
                playerSprite.move(-moveSpeed, 0);
            }
            else if (direction == 'R') {
                playerSprite.move(moveSpeed, 0);
            }
        }

    private:
        sf::Texture playerTexture;
        sf::Sprite playerSprite;
};

//if statement when they have to collide

if (ice.getGlobalBounds().intersects(Player.getGlobalBounds)) {
    cout << "the ice and the player sprite collided" << endl;
}

if (ice2.getGlobalBounds().intersects(Player.getGlobalBounds)) {
    cout << "the ice2 and the player sprite collided" << endl;
}

if (ice3.getGlobalBounds().intersects(Player.getGlobalBounds)) {
    cout << "the ice3 and the player sprite collided" << endl;
}

0 个答案:

没有答案