编译和启动后获得旧行为

时间:2017-05-28 01:26:02

标签: c++ visual-studio-2015 sfml

我之前设置了这个项目来测试SFML,它起作用,所以我删除了那段代码,并复制并粘贴了我做过的另一个项目的代码(制作了一个新的源文件和两个新的头文件)。

但是由于某种原因我不知道,一旦我使用我的新代码构建它,它仍会输出SFML测试..

Screenshot

另外:如果我点击构建 - >清理解决方案,它完全搞砸了我的整个项目,并且由于某种原因停止生成.exe文件,即使构建成功。

我尝试过的事情

  • 删除所有文件并替换它们。
  • 重新启动Visual Studio。
  • 输入其他代码,结果仍然相同。

这可能是一个小问题..

编辑:

int main() {
sf::RenderWindow window;

sf::Vector2i centerWindow((sf::VideoMode::getDesktopMode().width / 2), (sf::VideoMode::getDesktopMode().height / 2));

window.create(sf::VideoMode(900, 900), "JUMP TEST", sf::Style::Titlebar | sf::Style::Close);
window.setPosition(centerWindow);

window.setKeyRepeatEnabled(false);

//Player Object:             
Player player({ 40, 40 });
player.setPos({ 50, 500 });

//Coin Objects:
std::vector<Coin*> coinVec;
Coin coin1({ 20, 20 });
Coin coin2({ 20, 20 });
coinVec.push_back(&coin1);
coinVec.push_back(&coin2);

coin1.setPos({ 150, 300 });
coin2.setPos({ 300, 300 });

//Score Objects:
int score = 0;
int wSize;
sf::Font arial;
arial.loadFromFile("arial.ttf");

std::ostringstream ssScore;
ssScore << "Score: " << score;

sf::Text lblScore;
lblScore.setCharacterSize(30);
lblScore.setPosition({ 10, 300 });
lblScore.setFont(arial);
lblScore.setString(ssScore.str());

//Gravity Variables:
const int groundHeight = 720;
const float gravitySpeed = 1.0;
bool isJumping = false;
bool buttonPressed = false;

//Main Loop:
while (window.isOpen()) {

    sf::Event Event;

    const float jumpSpeed = 100.0f;
    const float moveSpeed = 1.0f;

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
        player.move({ moveSpeed, 0 });
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
        player.move({ -moveSpeed, 0 });
    }

    //Event Loop:
    while (window.pollEvent(Event)) {
        switch (Event.type) {

        case sf::Event::Closed:
            window.close();

        case sf::Event::EventType::KeyPressed:
            if (Event.key.code == sf::Keyboard::Key::Space)
            {
                isJumping = true;
                buttonPressed = true;
                player.move({ 0, -jumpSpeed });
            }
            break;
        case sf::Event::EventType::KeyReleased:
            if (Event.key.code == sf::Keyboard::Key::Space)
                isJumping = false;
            break;
        default:
            break;

        }
    }

    //Gravity Logic:
    if (player.getY() < groundHeight && isJumping == false && buttonPressed == true) {
    player.move({ 0, gravitySpeed });
    }
    //Player Collision
    if (player.getY() >= 500)
    {
        player.setPos({ player.getX(), 500 });
        isJumping = false;
    }

    //Coin Logic:
    for (int i = 0; i < coinVec.size(); i++) {
        if (player.isCollidingWithCoin(coinVec[i])) {
            coinVec[i]->setPos({ 422234, 423432 });
            score++;
            ssScore.str("");
            ssScore << "Score " << score;
            lblScore.setString(ssScore.str());
        }
    }


    window.clear();
    coin1.drawTo(window);
    window.draw(lblScore);
    coin2.drawTo(window);
    player.drawTo(window);
    window.display();
}

}

1 个答案:

答案 0 :(得分:2)

您的屏幕截图显示错误。所以你的程序根本没有构建。

Visual Studio随后为您提供了从上次编译时运行旧版本的选项。我想这就是你做的。 从不点击是。你不想要这个。我不知道谁认为这是有道理的。

确保您的程序编译没有错误。你应该看到正确的程序。