Hi there,
im boonstyle and im new to SFML. Before going into my problem i would lik to say that this library is pretty damn neat so keep up the good work. Its perfect for someone like me who always wanted to try out programing a game. As for me im working as programmer in the financial system working with properitary languages (sadly) so i got some kind of experience i guess
Now for the problem i went into:
I created a while loop which starts the functions from different classes according to an enum. Im using sf::Font and sf::Text to display some texts (obviously). The problem i did ran into is that as soon i start the function a second time i wont get the text rendered (drawing other objects works). I tried tinker around a little bit but i couldnt find any solution myself nor with the documentation.
the code looks something like this:
int game::start() {
title_screen title_screen; //the classes troubling
game_menu game_menu; //the classes troubling
//some code here
while (!game_exiting) {
switch (_game_state) {
case game_states::initializing:
cout << "initializing\n";
player.name = "unnamed"; //just tinkering around for placeholding
_game_state = game_states::title_screen;
break;
case game_states::title_screen:
cout << "entering title screen\n";
title_window.start(&_game_window, _game_state, game_setting.screen_res_x, game_setting.screen_res_y);
break;
case game_states::main_menu:
cout << "entering main menu\n";
game_menu.start(&_game_window, _game_state, game_setting.screen_res_x, game_setting.screen_res_y);
break;
case game_states::exiting:
game_exiting = true;
break;
default:
break;
}
}
//some code here
return 0;
}
void title_window::start(sf::RenderWindow * game_window, game::game_states& game_state, int size_x, int size_y) {
//some code here
//preload font
if (!screen_font.loadFromFile("arial.ttf"))
{
}
else {
std::cout << "Successfully loaded\n";
}
//some other code here
while (!exit_title_screen) {
//some event coding
if ( /* some fixed time steps */){
//more fixed time steps stuff here
game_window->clear();
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::White);
game_window->draw(shape); //darwing the shapes works perfect every time
screen_text.setFont(screen_font);
screen_text.setString("The Text");
screen_text.setPosition(sf::Vector2f(((size_x - 144) / 2) + 1, ((size_y - 36) / 2) + 1));
screen_text.setCharacterSize(30);
screen_text.setFillColor(sf::Color::White);
game_window->draw(screen_text); // this guy does not as i please :D
game_window->display();
};
};
}
I replaced all code which does not do affect the drawing to make this thing smaller here. The class does draw the text and the shape properly on first load. As soon i return to that loop i dont get the text anymore. The size_x and size_y arent touched anywhere so its still in the right place.
Btw. sorry for probably bad coding style (just started c++ and oop 3 days ago
)