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

Author Topic: How to make a functional main menu without headers?  (Read 3210 times)

0 Members and 1 Guest are viewing this topic.

irisetto

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
How to make a functional main menu without headers?
« on: January 04, 2022, 05:24:06 pm »
Hello! I am kind off new to sfml and im trying to do a menu that when i press the button "Help" or "Play" to open the corresponding window. I have different projects for the main menu, help and game window, without any headers, just 3 cpps. I dont know how to link the projects to the main menu buttons and if that is possible.

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: How to make a functional main menu without headers?
« Reply #1 on: January 04, 2022, 06:08:47 pm »
if there are just .cpp files, the IDE linker will put everything together when you compile it.
you will just need to declare (but not necessarily define) variables and classes in all files they are used.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

irisetto

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: How to make a functional main menu without headers?
« Reply #2 on: January 04, 2022, 07:15:08 pm »
I don't get it. the idea is that when I press the help button in main the menu window to open in the same window the cpp project from the help file

NeroGames

  • Full Member
  • ***
  • Posts: 101
  • Build games is simple
    • View Profile
    • Nero Game Engine
    • Email
Re: How to make a functional main menu without headers?
« Reply #3 on: January 04, 2022, 07:42:03 pm »
Hello irisetto,

If I get it, you've created three separate projects for each window (menu, help, game), which means you have three software (three executables) each one with its own game loop. If this is the case you are doing it wrong.

1 - You only need one project (one game loop, one executable)
2 - What you are trying to build is commonly called "Games States" and it can be done with a "State Machine" (it's not the only method though :) )
3 - You can search "SFML game state" or refer directly to the source code of SFML Game development book, chapter 5 https://github.com/SFML/SFML-Game-Development-Book
4- A simple solution would be to use "if else" or "switch" statement and draw only what needs to be drawn (menu, help, game)

« Last Edit: January 04, 2022, 07:47:15 pm by Sk Landry »

irisetto

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: How to make a functional main menu without headers?
« Reply #4 on: January 04, 2022, 07:46:26 pm »
How do I make one project from three. I'm struggling but I don't know how

NeroGames

  • Full Member
  • ***
  • Posts: 101
  • Build games is simple
    • View Profile
    • Nero Game Engine
    • Email
Re: How to make a functional main menu without headers?
« Reply #5 on: January 04, 2022, 07:55:20 pm »
you can do something like this, you switch between the states in your game loop

enum GameState {Menu, Play, Help}

GameState currentState = Menu;

while(true) //game loop
{
        switch (currentState )
        case : Menu
                inputMenu(); updateMenu(); drawMenu();
               
                if(buttonPlay) currentState = Play
                if(buttonHelp) currentState = Help

        case : Play
                inputPlay(); updatePlay(); drawPlay();
               
                if(buttonMenu) currentState = Menu
                if(buttonHelp) currentState = Help

        case : Help
                inputHelp(); updateHelp(); drawHelp();
               
                if(buttonMenu) currentState = Menu
                if(buttonPlay) currentState = Play
}
« Last Edit: January 04, 2022, 08:21:23 pm by Sk Landry »

 

anything