I picked up SFML 2 days ago as a graphic library and here is the problem.
I am wring a Scene system that Works ( i think it probably looks bad XD) the system works but I get disassembly errors when I am closing a window , I am 100% sure its because im Ignorant and hove no clue how SFML Windows work , I am hoping for some advice is possible .
Main
#include <SFML/Graphics.hpp>
#include "Classes.h"
using namespace std;
int screne = 2;
int main(int argc, char** argv)
{
// Different Scens tha I will use // Main menu etc..
Scene Scene1(sf::RenderWindow&);
Scene Scene2(sf::RenderWindow&);
Scene Scene3(sf::RenderWindow&);
Scene Scene4(sf::RenderWindow&);
// Create Window that takes Height and String for a Title
sf::RenderWindow window(sf::VideoMode(900, 500), "Game");
// Read on Windows and how it works cos im just buggin out the program when its finished
switch (screne)
{
case 1:
Scene1(window);
break;
case 2:
Scene2(window);
break;
case 3:
break;
case 4:
break;
}
return 1;
}
Scene Scene1(sf::RenderWindow& window) {
// The main loop - ends as soon as the window is closed
while (window.isOpen())
{
Pawn player;
sf::Sprite playerSprite;
player.setID(0);
player.setName("Steve");
player.setSpriteImg("Images/block.png");
playerSprite = player.getSprite();
// Event processing
sf::Event event;
while (window.pollEvent(event))
{
// Request for closing the window
if (event.type == sf::Event::Closed)
window.close();
}
// Clear the whole window before rendering a new frame
window.clear();
// Draw some graphical entities
window.draw(playerSprite);
// End the current frame and display its contents on screen
window.display();
}
}
Scene Scene2(sf::RenderWindow& window) {
// The main loop - ends as soon as the window is closed
while (window.isOpen())
{
Pawn player;
sf::Sprite playerSprite;
player.setID(1);
player.setName("bob");
player.setSpriteImg("Images/test.jpeg");
playerSprite = player.getSprite();
// Event processing
sf::Event event;
while (window.pollEvent(event))
{
// Request for closing the window
if (event.type == sf::Event::Closed)
window.close();
}
// Clear the whole window before rendering a new frame
window.clear();
// Draw some graphical entities
window.draw(playerSprite);
// End the current frame and display its contents on screen
window.display();
}
}
Classes.h
#include <SFML/Graphics.hpp>
#include <iostream>
// Pawn is a Controlable Objec in the game world
class Pawn{
private :
int ID; // ID to specifi it if needed
std::string Name; // Name of the object
sf::Texture Texture; // Texture for sprite
sf::Sprite Sprite; // Sprite
public :
void setSpriteImg(std::string filepath) {
if (!Texture.loadFromFile(filepath)) {
std::cout << "Error Load Failed" << std::endl;
}
Sprite.setTexture(Texture);
}
sf::Sprite getSprite() {
return Sprite;
}
int getID() {
return ID;
}
void setID(int id) {
ID = id;
}
void setName(std::string name) {
Name = name;
}
std::string getName() {
return Name;
}
};
class Scene {
private:
sf::RenderWindow window;
int ID;
public:
int getID() {
return ID;
}
};
u can try this code and tell me what im doing wrong haha .
thank you