Jump to content
  • Advertisement
Sign in to follow this  
Jan-PhilipQuirmbach

[SDL] Problem with Buttons

This topic is 2640 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,
i've got a problem with sdl when i use buttons. I've my menu with "Start", "Option" and "Exit" when i now click on start my game starts and the buttons are vanished but when i now click on the location where the button "exit" was my game exit.
How can i solve this problem?

thanks for your help

Share this post


Link to post
Share on other sites
Advertisement
One architectural solution is to divide the top level game into distinct states.

enum GameState
{
MenuState,
GameState,
Exit,
};

class Game
{
public:
GameState update();

void render();

private:
// ...
};

class Menu
{
public:
GameState update();

void render();

private:
// ...
};

int main()
{
init();

Menu menu;
Game game;

GameState current = Menu;
while(current != Exit)
{
GameState next = current;
switch(current)
{
case MenuState:
next = menu.update();
menu.draw();
break;

case GameState:
next = game.update();
game.draw();
break;

default:
// ...
break;
}

// If necessary
if(next != current)
{
if(next == GameState)
{
game = Game();
}
else if(next == MenuState)
{
menu = Menu();
}
current = next;
}
}
}

Some people would put the different states into classes/structures. This is nice because each state is self contained. The above is fine when you have a small state set.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!