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

Author Topic: The new font class  (Read 11792 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
The new font class
« Reply #15 on: March 17, 2008, 04:13:28 pm »
It should work. Can you show us your new code ?
Laurent Gomila - SFML developer

dbest

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • http://wow.origo.ethz.ch/
The new font class
« Reply #16 on: March 17, 2008, 04:27:54 pm »
The code is all over the place.. i hope thats not a problem..

main.cpp

Code: [Select]
int main()
{
      /// Create the main window
    sf::RenderWindow App;

    App.Create(sf::VideoMode(SCREENWIDTH, SCREENHEIGHT, 32), "SFML Window", sf::Style::Fullscreen);

    CText Text;
....
....
Text.Plot(App,"UITILE", 200,0,128,200,10,15);



text.h

Code: [Select]
class CText {
    private:
    sf::String TextString;
    sf::Font Font;

    public:
    CText();
    ~CText();

    ///Create text string with size and color
    void Plot(sf::RenderWindow& App, char text[10], int r, int g, int b, int x, int y, int size=20);
};


text.cpp

Code: [Select]
#include "Text.h"

CText::CText()
{
  Font.LoadFromFile("cheeseburger.ttf");
  sf::String TextString(L"",Font);
}

CText::~CText()
{
}


void CText::Plot(sf::RenderWindow& App, char text[10], int r, int g, int b, int x, int y, int size)
{
     //sf::String TextString(L"",Font);
    TextString.SetText(text);
    TextString.SetSize(size);
    TextString.SetColor(sf::Color(r,g,b));
    TextString.SetPosition(x,y);

    App.Draw(TextString);
}


If i uncomment the sf::String TextString(L"",Font); line in the Plot function, then the cheeseburger.ttf font is used, else the default font is used.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
The new font class
« Reply #17 on: March 17, 2008, 04:45:10 pm »
Quote
sf::String TextString(L"",Font);

Here you're declaring a new variable which has nothing to do with the member of your class, and will be destroyed at the end of the constructor ;)
Laurent Gomila - SFML developer

dbest

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • http://wow.origo.ethz.ch/
The new font class
« Reply #18 on: March 17, 2008, 07:09:29 pm »
Got it thanks...
fixed it with
Code: [Select]
TextString.SetFont(Font); in the constructor.


Thanks a lot.. :)