SFML community forums
Help => General => Topic started by: Mykal on February 08, 2017, 08:04:10 pm
-
I am working on a game and am planning on creating a text management class that will basically place text anywhere on the screen. I am trying to use a class member variable of sfml type as a parameter and I can figure out how to make it work. below is a few snippets of code.
text manager class function
void TextManager::SetUpText(sf::Text text, sf::FloatRect text_rect, sf::Color color, std::string word, int size, sf::Font, float width, float height)
{
text.setString(word);
text.setFillColor(color);
text.setCharacterSize(size);
text_rect = text.getLocalBounds();
text.setOrigin(text_rect.left + text_rect.width / 2.0f,
text_rect.top + text_rect.height / 2.0f);
text.setPosition(sf::Vector2f(width / 2.0f, height / 4.0f));
}
I'm trying to use this function in one of my title screen class functions, but the parameters I'm entering aren't working.
these are the title screen member variables I'm trying to use
sf::Font start_Font;
sf::Text start_Title_Text;
sf::FloatRect start_Title_TextRect;
I'm trying to use them in the function from the text manager class
here is the function in the title screen class
void StartScreen::SetUpScreen(int width, int height)
{
start_BACKGROUND.loadFromFile("Background.png");
start_Font.loadFromFile("Title.ttf");
start_Title_Text.setFont(start_Font);
SetUpText(start_Title_Text, start_Title_TextRect, sf::Color::White, "Title", 72, start_Font, width, height);
}
but the start_Title_Text, start_Title_TextRect and start_Font are all saying
"no suitable user-defined conversion from sf::type" to "TitleScreen" exists"
-
Wouldn't you need to do
TextManager::SetUpText
instead? Is the TextManager class method static or does it need an object to be used?
If there is no actual TextManager object, you can just place that method in a namespace and have the function available globally.
You say your class is called "TitleScreen"(?) but you have "StartScreen::SetUpScreen".
-
An instance that you intend to modify in a function must be passed by reference.
-
Thanks! that worked Laurent!.. hmm that's an interesting idea with the namespaces, maybe ill have to try that method out jayhawk and see which way works better