未处理的异常 C++ SFML

问题描述

我目前正在制作我的 2D 游戏,但我有一个我不明白的错误,这是错误的屏幕截图: enter image description here

这是主要的代码

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

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

int main(RenderWindow &window,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,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"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...