I've removed most of the code in the game-loop and added a short piece of code that will decrease a counter for about the same amount of time as it took for the wheels to stop spinning:
while(1)
{
sf::Event eEvent;
while(App.GetEvent(eEvent))
{
if(eEvent.Type != 10)
std::cout << eEvent.Type << std::endl;
if(eEvent.Type == sf::Event::KeyPressed && eEvent.Key.Code == sf::Key::Escape)
exit(EXIT_SUCCESS);
else if(eEvent.Type == sf::Event::MouseButtonPressed && eEvent.MouseButton.Button == sf::Mouse::Left)
{
int mouseX = App.GetInput().GetMouseX();
int mouseY = App.GetInput().GetMouseY();
int hit = -1;
for(int i = 0; i < 5; i++)
{
if(v_iClickables[i].Contains(mouseX, mouseY)) //check clickable regions
{
hit = i; //button i was pressed
break;
}
}
//if a button was pressed, act accordingly
switch(hit)
{
case 0: exit(EXIT_SUCCESS);
case 2: if(!bIsSpinning) //if wheels are not spinning, start spinning
{
for(int i = 0; i < signed(v_iWheelsLeftToSpin.size()); i++)
spin += sf::Randomizer::Random(5, 19);
spin += 10;
bIsSpinning = true; //the wheels are spinning
}
break;
}
}
}
//New code
if(spin <= 0)
bIsSpinning = false;
else
{
offset = (offset + 1) % 96;
if(offset == 0)
spin -= 2;
}
//New code end
std::stringstream ss2;
ss2 << spin;
sf::String str(ss2.str());
str.SetPosition(10.f, 10.f);
App.Draw(str);
App.Display();
}
Even this short code fails to work. Does the time waiting for the wheels to stop/counter to reach 0 (this example) cause the window to lose focus? Seems weird to me.
Is visual studio forcing the window to have focus as the problem doesn't appear debugging it?