Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I need some help with a Scene system ... Im a newbie  (Read 2626 times)

0 Members and 1 Guest are viewing this topic.

Vegger

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
I need some help with a Scene system ... Im a newbie
« on: November 06, 2018, 12:05:24 am »
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
Code: [Select]

#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
Code: [Select]
#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




« Last Edit: November 06, 2018, 12:18:32 am by Vegger »

Hapax

  • Hero Member
  • *****
  • Posts: 3346
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: I need some help with a Scene system ... Im a newbie
« Reply #1 on: November 07, 2018, 10:46:32 pm »
You should probably post your errors so that people know what it is that is going wrong.

Although, one thing I noticed is that there doesn't seem to be much use of the Scene class. You're not even returning one from the function that should nor are you using the Scene that should be returned. Those functions should probably be declared in global scope (above main).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything