how to creating maiin menu on the stack

  • coder007
    Likes 0

    Problem Description

    so i am following tic tac toe tutorial on youtube. now i have wrote all the code from the state machine to the states but i decided instead of starting with a splash screen i’d go straight to the main menu. I’m trying to add the state to the stack but it gives me this error:

    ”Error (active) object of abstract class type "HoodiniGames::MainMenu" is not allowed”

    here is my mainmenu.h

    namespace HoodiniGames {

    class MainMenu: public State
    {
    public:
     MainMenu(gamedataRef data);
     ~MainMenu();
     void init();
     void update(float dt);
     void HandleInput();
     void draw(float dt);
    
     void moveUp();
      void moveDown();
     int getpressedItem() { return selectedindex; }
     void setPressedItem(int index) { selectedindex = index; }
      sf::RectangleShape getexitgameButton() { return exitGame; };
    
     private:
     int selectedindex;
     sf::Font font;
     sf::Text text[MAX_NUMBER_ITEMS];
     sf::RectangleShape singlePlayer;
     sf::RectangleShape multiPlayer;
     sf::RectangleShape exitGame;
     sf::Event event;
     gamedataRef _data;
    
    };
    
    }
    

    i try creating the object in the game.cpp

     namespace HoodiniGames
     {
    HoodiniGames::Game::Game(int width, int height, string title)
    {
        _data->window.create(sf::VideoMode(width, height), title, sf::Style::Close | sf::Style::Titlebar);
    
        _data->state.AddState(stateRef(new MainMenu(_data)),true);//<----  error occurs here 
    
        this->Run();
    }
    

    the mainmenu class inherits from the state (which is a abstract class) so why is the mainmenu recognized as an abstract class

  • Sonar Systems admin
    Likes 0

    Confirm the code from the state machine is exactly the same.

Login to reply