Hey I need some Help with this code.. Whenever I run it I get a runtime error. Can somone help me?
//Here is My menu system
#include <iostream>
#include <string>
#include <SFML\Graphics.hpp>
using namespace std;
void NewGame()
{
cout << "NewGame" << endl;
}
void Controls()
{
cout << "Controls" << endl;
}
void Exit()
{
cout << "Exit" << endl;
}
class spawnMenu
{
public:
spawnMenu(string options)
{
fake_options.SetText(options);
/*if(functions == "NewGame")
{
NewGame();
}
if(functions == "Controls")
{
Controls();
}
if(functions == "Exit")
{
Exit();
}*/
}
void setcolor(int red, int blue, int green)
{
fake_options.SetColor(sf::Color(red,blue,green));
}
void setposition(int x, int y)
{
fake_options.SetPosition(x,y);
}
void setsize(int size)
{
fake_options.SetSize(size);
}
void setfont()
{
sf::Font font;
if (!font.LoadFromFile("batmfa_.ttf"))
{
cout << "Error" << endl;
}
fake_options.SetFont(font);
}
void setdefault()
{
sf::Font font = sf::Font::GetDefaultFont();
fake_options.SetFont(font);
fake_options.SetSize(14);
}
/*void draw_menu()
{
App.Draw(fake_options);
}*/
sf::String fake_options;
string options;
string functions;
string input;
};
ANd My main..
#include <SFML\Graphics.hpp>
#include <iostream>
#include "textmenu.h"
int main()
{
sf::RenderWindow App;
App.Create(sf::VideoMode(800,600,8),"MenuTester");
sf::Image iBackground;
if(!iBackground.LoadFromFile("Background.png"))
{
cout << "Error" << endl;
}
sf::Sprite Background(iBackground);
spawnMenu mainmenu[3] =
{
spawnMenu("NewGame"),
spawnMenu("Controls"),
spawnMenu("Exit")
};
/* mainmenu[0].options = "NewGame";
mainmenu[1].options = "Controls";
mainmenu[2].options = "Exit";
*/
mainmenu[0].functions = "NewGame";
mainmenu[1].functions = "DispControls";
mainmenu[2].functions = "Exit";
mainmenu[0].setcolor(255,0,0);
mainmenu[1].setcolor(255,0,0);
mainmenu[2].setcolor(255,0,0);
mainmenu[0].setposition(250,250);
mainmenu[1].setposition(250,350);
mainmenu[2].setposition(250,450);
mainmenu[0].setsize(14);
mainmenu[1].setsize(14);
mainmenu[2].setsize(14);
mainmenu[0].setfont();
mainmenu[1].setfont();
mainmenu[2].setfont();
/*
mainmenu[0].setdefault();
mainmenu[1].setdefault();
mainmenu[2].setdefault();
*/
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
}
// Clear the screen (fill it with black color)
App.Clear();
App.Draw(Background);
App.Draw(mainmenu[0].fake_options);
App.Draw(mainmenu[1].fake_options);
App.Draw(mainmenu[2].fake_options);
// Display window contents on screen
App.Display();
}
}