iam trying to make a menu
i need to check if the user pressed a button to move throw the menu
when i tried doing this function then calling it in main
if (Keyboard::isKeyPressed(Keyboard::S))
{
selectedText[selectedNum].setFillColor(Color::White);
selectedNum++;
selectedText[selectedNum].setFillColor(Color::Blue);
}
the it goes throw all menu then the program crash
else if i use
if (event.type == Event::KeyPressed && event.key.code == Keyboard::S)
menu.moveDown();
it works fine
so what is the difference between these two ways what did ido wrong
iam trying to make a menu
i need to check if the user pressed a button to move throw the menu
when i tried doing this function then calling it in main
if (Keyboard::isKeyPressed(Keyboard::S))
{
selectedText[selectedNum].setFillColor(Color::White);
selectedNum++;
selectedText[selectedNum].setFillColor(Color::Blue);
}
the it goes throw all menu then the program crash
else if i use
if (event.type == Event::KeyPressed && event.key.code == Keyboard::S)
menu.moveDown();
it works fine
so what is the difference between these two ways what did ido wrong
In the first code u're not relying on events. Probably ur index goes too high and this is why it crashes. The same happens on the second, but since it reacts on-event (not on-frame) it is executed fewer times and index doesn't reach the end