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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - fuhrermag

Pages: [1]
1
Hmm. Try this:

Text Game::createText(Font &f, const String &string) {
        Text text;
        text.setFont(f);
        text.setString(string);
        return text;
}


// lines more

        Font font;
        font.loadFromFile("fonts/ARCADECLASSIC.ttf");

        Text text1 = createText(font, "PLAY");
 

(Pass the font by reference instead of by value)
Not sure if this will fix it, but again, I think it's worth a shot :)


This worked. Thank you very much !

2
Nah mate, Sadly this didn't work. I get the same error

Text Game::createText(Font f, const String &string) {
        Text text;
        text.setFont(f);
        text.setString(string);
        return text;
}

// lines more

        Font font;
        font.loadFromFile("fonts/ARCADECLASSIC.ttf");

        Text text1 = createText(font, "PLAY");
 

3
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?

Pages: [1]