I'm have a bit of trouble as the title suggests. I've got three sprites inside of a vector. I'm building a button system for an application. The code detects which sprite is being selected, but does not show the changes. Wierd thing is-is if I change the vector component target to a specific sprite the color change works. Does anyone know whats going on here?
unsigned int selected = -1;
// Load Sprite Vector
vect.push_back(S1);
vect.push_back(S2);
vect.push_back(S3);
// Application Loop
while (Running){
//--EVENTS--
while (App.pollEvent(Event)){
... Event handler
else if (Event.type == Event.MouseButtonPressed && Event.mouseButton.button == sf::Mouse::Left){
for (unsigned int i = 0; i < vect.size(); i++){
if (ifspritecollision(vect[i], mouse.x, mouse.y)){
vect[i].setColor(sf::Color(120, 120, 120));
selected = i;
break;
}
}
}
else if (Event.type == Event.MouseButtonReleased && Event.mouseButton.button == sf::Mouse::Left){
// There are only three sprites on the screen
if (!(selected < 0 || 2 < selected))
vect[selected].setColor(sf::Color(255, 255, 255));
}
//... clear screen
//... draw to screen
//... display screen
}
This will work for a single sprite
else if (Event.type == Event.MouseButtonPressed && Event.mouseButton.button == sf::Mouse::Left){
for (unsigned int i = 0; i < vect.size(); i++){
if (ifspritecollision(vect[i], mouse.x, mouse.y)){
// target for color change set to a specific sprite
S1.setColor(sf::Color(120, 120, 120));
selected = i;
break;
}
}
}
else if (Event.type == Event.MouseButtonReleased && Event.mouseButton.button == sf::Mouse::Left){
// There are only three sprites on the screen
if (!(selected < 0 || 2 < selected))
// target for color change set to a specific sprite
S1.setColor(sf::Color(255, 255, 255));
}
P.S The code has been changed for simplicity.