Ok, before you say it I am OK with C++ but when it comes to pointers, threads, multi-d arrays and other things I am noob... I know they're important but I haven't learned it as of now...
Well I am using sf::Thread not std::Thread
The problem is I am "pausing" the thread but it jut pauses the main thread!
I Will Post my code below please help
.
This file is called mainScreen.cpp it represents my Main Menu.
The problem is with the thread that changes the bottom message color.
(If I call it without the sf::sleep or as not being a thread the colors just change instantaneously (obviously))
#include "mainScreen.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include "variables.h"
#include "textCreator.h"
#include "Funcs.h"
#include <dos.h>
#include <SFML/System.hpp>
/*NOTE: sf::Vector2f = (width, height)*/
void changeBtmMessageTextColor(int x);
void scrollBtmMessage();
sf::RectangleShape playBTN;
sf::Text playBTNText;
sf::Texture mainMenuTexture;
sf::Sprite mainMenuImg;
sf::Text creator;
int bottomMsgColor = 1; //1 = green, 2 = yellow, 3 = red
sf::Thread scroller(&scrollBtmMessage);
sf::Thread colorScroller(&changeBtmMessageTextColor, bottomMsgColor);
void changeBtmMessageTextColor(int x) //this is the block of code with problems!
{
if(x==1)
{
creator.setColor(sf::Color::Yellow);
sf::sleep(sf::milliseconds(1500));
}
if(x==2)
{
creator.setColor(sf::Color::Red);
sf::sleep(sf::milliseconds(1500));
}
if(x==3)
{
creator.setColor(sf::Color::Green);
sf::sleep(sf::milliseconds(1500));
}
sf::sleep(sf::milliseconds(1500));
}
void scrollBtmMessage()
{
if(creator.getPosition().x >= fullscreen.width){
creator.setPosition(0-3500,creator.getPosition().y);
}
else{
creator.setPosition(creator.getPosition().x+2,creator.getPosition().y);
}
}
void mainScreen::drawMainScreen(sf::RenderWindow *window)
{
isMainScreenOn=true;
if(isMainScreenBuilt == false)
{
//playBTN
playBTN.setSize(sf::Vector2f((fullscreen.width*0.35),(fullscreen.height*0.10)));
playBTN.setPosition((funcs::findCenterOfScreenWidth(fullscreen.width)) - ((fullscreen.width*0.35)/2),fullscreen.height*0.45);
playBTN.setFillColor(sf::Color::White);
//playBTNText
//textCreator::createText(playBTNText, mainFont, sf::Color::Green, "New Game", ((fullscreen.width*0.35)/2), ((fullscreen.height*0.10)/2));
playBTNText.setColor(sf::Color::Black);
playBTNText.setFont(mainFont);
playBTNText.setString("Play Game");
playBTNText.setPosition(funcs::findCenterOfScreenWidth(fullscreen.width)-90,(fullscreen.height*0.45)+((fullscreen.height*0.10)/PI));
//mainMenuImg
mainMenuTexture.loadFromFile("Images\\main_menu_img.png");
mainMenuImg.setTexture(mainMenuTexture);
mainMenuImg.setPosition(funcs::findCenterOfScreenWidth(fullscreen.width)-(1000/2),fullscreen.height*0.05);
//creator
creator.setColor(sf::Color::Green);
creator.setFont(mainFont);
creator.setString("Made by : MW2TopTenWORLD a.k.a MW2T1999 || Subscribe me at http://www.youtube.com/mw2toptenworldmodz (Click this message to go there!) || Thank You For Purchasing my Game or whatever...");
creator.setPosition(0, fullscreen.height-(fullscreen.height*0.05));
isMainScreenBuilt = true;
}
window->draw(playBTN);
window->draw(playBTNText);
window->draw(mainMenuImg);
window->draw(creator);
colorScroller.launch();
//changeBtmMessageTextColor(bottomMsgColor);
scroller.launch();
if(bottomMsgColor!=3){
bottomMsgColor++;
}else{
bottomMsgColor=1;
}
}
Please Help