Hello. I am working on a 2D game and now I'm dealing with the menu. I want it to have 3 text boxes.
Yes, I can do this:
Font font;
Text text1;
font.loadFromFile("fonts/ARCADECLASSIC.ttf");
text1.setFont(font);
text1.setString("PLAY");
text1.setCharacterSize(50);
Text text2;
text2.setFont(font);
text2.setString("OPTIONS");
text1.setCharacterSize(60);
Text text3;
text3.setFont(font);
text3.setString("EXIT");
text1.setCharacterSize(70);
It works, but it occupies too much space. So I thought I can make a function and instead of 12 lines I can use just 3:
Text Game::createText(const String &string, unsigned int size) {
Font font;
Text text;
font.loadFromFile("fonts/ARCADECLASSIC.ttf");
text.setFont(font);
text.setString(string);
text1.setCharacterSize(size);
return text;
}
// some lines more
Text text1 = createText("PLAY", 50);
And now, I want to display text1:
window.draw(text1);
And here's the problem! I get this error:
"Unhandled exception at 0x00007FFBCF11682B (sfml-graphics-d-2.dll) in SFML Program.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.", and it shows an "X" on the line with "window.draw(text1);".
And no, it's not because I didn't put an if statement at "font.loadFromFile...". The font loads. It's another problem that I don't get it. Any help?