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

Author Topic: String Class  (Read 3622 times)

0 Members and 1 Guest are viewing this topic.

Shay9999

  • Newbie
  • *
  • Posts: 24
    • View Profile
String Class
« on: June 09, 2011, 04:23:10 am »
I have a problem with the String class. I get an Error saying that certain functions such as SetFont and SetScale are not part of sf::String class. I want to be able to draw text onto the screen

Code: [Select]
sf::RenderWindow Window;
...
Window.Draw (Text);


but this problem is getting me into some errors. This is what I have so far along with the lines above:
Code: [Select]
sf::String Text = "Nacho Cheese";
Text.SetFont(sf::Font::GetDefaultFont());
Text.SetScale(2.f, 2.f);


I have a feeling the error has something to do with making a Text class item, but I have no idea. Anyone know what I'm doing wrong?
C++-Trainee
SFML-Trainee

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
String Class
« Reply #1 on: June 09, 2011, 06:58:13 am »
you want sf::Text
John Carmack can Divide by zer0.

Shay9999

  • Newbie
  • *
  • Posts: 24
    • View Profile
String Class
« Reply #2 on: June 09, 2011, 07:11:05 am »
I changed the code to:

Code: [Select]
sf::Text Text - "Meet Gary";
Text.SetFont(sf::Font::GetDefaultFont());

Window.Draw(Text);


and I got this error:
Quote
1>c:\users\desktop\visc++\Project\Project\main.cpp(13) : error C2440: 'initializing' : cannot convert from 'const char [10]' to 'sf::Text'
1>        Constructor for class 'sf::Text' is declared 'explicit'
C++-Trainee
SFML-Trainee

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
String Class
« Reply #3 on: June 09, 2011, 07:26:36 am »
The message says everything: The constructor is explicit, i.e. the const char* has to be passed as constructor argument:
Code: [Select]
sf::Text text("Meet Gary");
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Shay9999

  • Newbie
  • *
  • Posts: 24
    • View Profile
String Class
« Reply #4 on: June 09, 2011, 07:54:44 am »
Changed it to:

Code: [Select]
sf::Text text = ("Meet Gary");
text.SetFont(sf::Font::GetDefaultFont());
Window.Draw(text);


and received:
Quote
1>c:\users\desktop\visc++\Project\Project\main.cpp(14) : error C2440: 'initializing' : cannot convert from 'const char [10]' to 'sf::Text'
1>        Constructor for class 'sf::Text' is declared 'explicit'
C++-Trainee
SFML-Trainee

Lokk

  • Full Member
  • ***
  • Posts: 228
    • View Profile
    • http://betadineproject.wordpress.com/
String Class
« Reply #5 on: June 09, 2011, 09:01:23 am »
Read again Nexus's post ^^

Fouf

  • Newbie
  • *
  • Posts: 23
    • View Profile
String Class
« Reply #6 on: June 09, 2011, 05:36:56 pm »
You want.. sf::String

Code: [Select]
sf::String Text("Nacho Cheese");
   Text.SetFont(sf::Font::GetDefaultFont());
   Text.SetScale(2.f, 2.f);

You must initalize Text like that so it calls the constructor to initalize the text inside the string.. you could also

Code: [Select]
sf::String Text;
Text.SetText("Cheese");
...



oh... I haven't used 2.0 yet.. so I guess it is sf::Text.. disregard this I guess, unless you are using 1.6. :\..
I guess I should try 2.0....
- Fouf

 

anything