Ah thanks for that, too used to doing things manually forgot to check if there was a "contains" function. I took out the logging stuff from the posted code but have re-added it below with your suggestion and the output. Realised i was only checking if it worked changing the iterator though. I've added code to hard check the playButton which isnt being changed so it seems changing the iterator isnt kicking back to the original list. Will i then have to cast the iterator back to the menu some how to make it work?
void StartMenu::initiate(TextureManager &resManager)
{
playButton.sprite.setTexture(resManager.getTexture("images/mainMenuButtons.png"));
playButton.defaultRect = sf::IntRect(0,0,200,50);
playButton.hoverRect = sf::IntRect(0,50,200,50);
playButton.sprite.setTextureRect(playButton.defaultRect);
}
void StartMenu::update(sf::RenderWindow &renderWindow, sf::Event &event, float &delta)
{
HandleHover(renderWindow);
std::cout<<"update play button: "<< playButton.sprite.getTextureRect().top <<std::endl;
renderWindow.draw(playButton.sprite);
}
void StartMenu::HandleHover(sf::RenderWindow &renderWindow)
{
int x = sf::Mouse::getPosition(renderWindow).x;
int y = sf::Mouse::getPosition(renderWindow).y;
std::list<MenuItem>::iterator it;
for(it = menuItems.begin(); it != menuItems.end(); ++it)
{
if ((*it).rect.contains(x,y))
{
it->sprite.setTextureRect((*it).hoverRect);
std::cout<<"handle hover iterator: "<< it->sprite.getTextureRect().top <<std::endl;
std::cout<<"handle hover play button: "<< playButton.sprite.getTextureRect().top <<std::endl;
}
else
{
it->sprite.setTextureRect((*it).defaultRect);
}
}
}
####### OUTPUT #########
handle hover iterator: 50
handle hover play button: 0
update play button: 0