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

Author Topic: Need Some Help With this universal Menu System  (Read 1900 times)

0 Members and 1 Guest are viewing this topic.

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Need Some Help With this universal Menu System
« on: November 10, 2010, 03:33:36 am »
Hey I need some Help with this code.. Whenever I run it I get a runtime error. Can somone help me?  

Code: [Select]

//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..
Code: [Select]
#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();
}
}

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Need Some Help With this universal Menu System
« Reply #1 on: November 11, 2010, 03:49:24 am »
Hey I know what is wrong, The part where I draw the text to the screen. I just need to know how to fix it. it something wrong with the memory allocation

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Need Some Help With this universal Menu System
« Reply #2 on: November 11, 2010, 09:23:56 am »
You set the font of your text and then immediately destroy it. When you draw the text, it uses a font that no longer exists. You must store the font as long as the text uses it.
Laurent Gomila - SFML developer

Fierce_Dutch

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Need Some Help With this universal Menu System
« Reply #3 on: November 12, 2010, 01:39:08 am »
Well I already found what was wrong from someone else and it was because of something about it being static and doing that.

 

anything