c++ - 未处理的异常 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"
解决方案
推荐阅读
- python - 关于从标准输入随机化的 Python 问题
- c# - 使用 EF 防止公开更改收集内容
- pandas - 无法将 csv 文件读入熊猫
- python - 你能在类中添加猴子补丁吗?如果没有,我如何重载一个运算符来为两个不同的类定义加法?
- google-cloud-platform - 无法在 Google 计算引擎中作为启动脚本的一部分挂载外部永久性磁盘
- arrays - MongoDB - 更新文档在基于乘法字段*常量的数组中添加新项目
- python - 使用 python 打开一个新的 xterm 窗口来运行另一个脚本,然后尝试使用 Ctrl+C 杀死
- python - 为什么我的 loc() 函数的输出仍然显示我试图过滤掉的值?
- asp.net - CKEditor 不传输写入数据库的内容
- jquery - 如何通过formdata()传递多个文件值