Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

unhandled exception C++ SFML

im currently making on my 2D game and i have a error that i dont understand, here is screenshot of the rror: enter image description here

here is code for main:

#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);

}

}

code for Player.H:

#pragma once

#include "Game.h"

class Player {

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

};

code for 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);

}

}

and then i have Game.H just to include stuff and for the future, here is code for 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 {



};

and then empty Game.cpp:

#include "Game.h"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...