Thanks so much expl0it3r. I got my fade to work by calling the update function of my ScreenManager and Animation classes which update the alpha values and screens. But i still have questions because some things still seem a bit strange.
First heres my main loop right now.
bool enableKeyRepeat = false;
sf::RenderWindow Window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32),"Hulq", sf::Style::None);
Window.clear(sf::Color(0, 0, 0));
Window.setFramerateLimit(60);
Window.setKeyRepeatEnabled(enableKeyRepeat);
ScreenManager::getInstance().initialize();
ScreenManager::getInstance().loadContent();
sf::Clock clock;
while(Window.isOpen()){
while(Window.pollEvent(ScreenManager::getInstance().event)){
switch (ScreenManager::getInstance().event.type){
case sf::Event::Closed:
Window.close();
break;
case sf::Event::KeyPressed:
if(ScreenManager::getInstance().event.key.code == sf::Keyboard::Escape) {
Window.close();
}//if escape is pressed close window and skip everything in loop
else
ScreenManager::getInstance().update(ScreenManager::getInstance().event, Window);
break;
default:
ScreenManager::getInstance().update(ScreenManager::getInstance().event, Window);
}//end of switch(event.type)*/
}//end of while Poll event
Window.clear(sf::Color(0, 0, 0));
/****/ScreenManager::getInstance().update(ScreenManager::getInstance().event, Window);
ScreenManager::getInstance().draw(Window);
Window.display();
ScreenManager::getInstance().timeBetwFrame = clock.restart(); //records time between frame
}//end of while isOpen
The fade in and out only works if i put the line with /****/ in. if i take that line out it doesnt work. basically if i take that line out, i have to continuously press the return key (which switches screens) in order to fade in and out. if i put the line in, then i can press the return key once and it will fade out, switch screens, and fade the new screen in. I have read the events tutorial. From what i deduced, if no event is happening it wont even go inside the while(pollEvent()) and it will just keep looping the while(isOpen()) loop. And my update() function is called inside the while(pollEvent()). So i made a call to update outside (the /****/ line). is this a good way to do things?
Let me try to give u the jist of what im doing. my update function updates everything. screen and alpha too. once the Return key is pressed itll start the fade animation. A bool value called "inTransition" will become true and while thats true it will keep doing the fade animation as long as update() is called. basically to keep changing the alpha value (make it go from 0 to 255 and back to 0 to effectively fade out and then fade in) update() must be called which checks the bool inTransition to see if its true and if true, it proceeds to change the alpha value. now, if i press Return and then dont press anything else, update() wont be called unless i bring it outside to the while(isOpen()) loop. however it makes more sense to keep it only inside the while(pollEvent()) loop because you update() based on whether there are events or not. and yes i did take your advice, and my update function draws various things to the window but i only call Window.display() once. i looked at your SmallGameEngine and it seems your using a stack to push and pop states. it seems kind of advanced and i dont quite understand how you fade in your IntroState. You reduce the alpha value everytime it loops irrespective of keypresses. Its really clean code but i havent really used stacks. How exactly do you use stacks in a game? Doesnt while(pollEvent()) push and pop events for you? And does C++ only support .hpp headers? i used .h headers for my headers.
also sorry i keep bombarding with questions. for my titlescreen i just draw sf::Text to the screen. is there any easy way to center the text in the center of the window? right now im doing this.
text.setPosition(SCREEN_WIDTH/2 - ( (stringLength/3) * text.getCharacterSize()), SCREEN_HEIGHT/2 - text.getCharacterSize());
as you can see, its completely random guessing with numbers. i understand i could load an image with a sprite, but i think id run into the same problem centering a sprite.
btw how do you change a thread to [SOLVED]?
i apologize for the huge essay post.