Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualCrusable

Posted 18 April 2013 - 11:09 PM

Hello, I am working on a menu for my game and the buttons only activate when clicking in specific areas such as the middle bottom and the middle left side.

 

 

 
bool Aliens::Button::HandleEvents(sf::Event Event){
 
float MouseX = Event.mouseMove.x;
float MouseY = Event.mouseMove.y;
 
if(Event.type == sf::Event::MouseMoved){
 
if((MouseX >= mButtonSprite.getPosition().x) && (MouseX <= mButtonSprite.getPosition().x + mButtonBox.x) &&
(MouseY >= mButtonSprite.getPosition().y) && (MouseY <= mButtonSprite.getPosition().y + mButtonBox.y)){
 
mButtonSprite.setTexture(mMouseOverTexture);
 
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) return true;
}
 
else mButtonSprite.setTexture(mNormalTexture);
}
 
return false;
}

 

 

Thanks for any help.


#1Crusable

Posted 18 April 2013 - 11:07 PM

Hello, I am working on a menu for my game and the buttons only activate when clicking in a specific area.

 

 
bool Aliens::Button::HandleEvents(sf::Event Event){
 
float MouseX = Event.mouseMove.x;
float MouseY = Event.mouseMove.y;
 
if(Event.type == sf::Event::MouseMoved){
 
if((MouseX >= mButtonSprite.getPosition().x) && (MouseX <= mButtonSprite.getPosition().x + mButtonBox.x) &&
(MouseY >= mButtonSprite.getPosition().y) && (MouseY <= mButtonSprite.getPosition().y + mButtonBox.y)){
 
mButtonSprite.setTexture(mMouseOverTexture);
 
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) return true;
}
 
else mButtonSprite.setTexture(mNormalTexture);
}
 
return false;
}

 

 

Thanks for any help.


PARTNERS