首页 > 解决方案 > 未处理的异常 C++ SFML

问题描述

我目前正在制作我的 2D 游戏,但我有一个我不明白的错误,这是错误的屏幕截图: 在此处输入图像描述

这是主要的代码:

#include "Game.h"
#include "Player.h"

void Run(RenderWindow &window, Sprite &player, Texture &PlayerTex);

int main(RenderWindow &window, Sprite &player, Texture &PlayerTex) {

Run(window, player, PlayerTex);

return 0;
}

void InitWindow() {

RenderWindow window(VideoMode(1920, 1080), "Discord Game");

}

void Update() {



}

void Render(RenderWindow &window, Sprite &player) {

player.setScale(0.3f, 0.3f);

window.clear(Color::White);
window.draw(player);
window.display();

}

void Run(RenderWindow &window, Sprite &player, Texture &PlayerTex) {

InitWindow();

while (window.isOpen()) {

    Event sfEvent;
    while (window.pollEvent(sfEvent)) {

        if (sfEvent.type == Event::Closed)
            window.close();

    }

    Update();
    Render(window, player);
    Player P;
    P.PlayerMovement(player);

}

}

Player.H 的代码:

#pragma once

#include "Game.h"

class Player {

public:
    Sprite player;
    Texture PlayerTex;
    void PlayerTexture(Sprite &Player, Texture &PlayerTex);
    void PlayerMovement(Sprite &Player);

};

Player.cpp 的代码:

#include "Game.h"
#include "Player.h"

void Player::PlayerTexture(Sprite& player, Texture& PlayerTex) {

PlayerTex.loadFromFile("textures/Player/PlayerFront.png");
player.setTexture(PlayerTex);

}

void Player::PlayerMovement(Sprite &player) {

if (Keyboard::isKeyPressed(Keyboard::A)) {

    
    player.move(-5.f, 0.f);

}

if (Keyboard::isKeyPressed(Keyboard::D)) {

    player.move(5.f, 0.f);

}

if (Keyboard::isKeyPressed(Keyboard::W)) {

    player.move(0.f, -5.f);

}

if (Keyboard::isKeyPressed(Keyboard::S)) {

    player.move(0.f, 5.f);

}

}

然后我有 Game.H 只是为了包含一些东西,为了将来,这里是 Game.h 的代码:

#pragma once

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
using namespace sf;

class Game {



};

然后清空 Game.cpp:

#include "Game.h"

标签: c++sfmlunhandled-exception

解决方案


推荐阅读