1
Graphics / Detect click of a button on a matrix of buttons
« on: March 27, 2009, 06:53:18 am »
Hi there...
I' am newbie with SFML and have some dudes...
I want detect click in the matrix buttons (Button = sprite, with some things changed)...
This code make the detection of mouse click on area of sprite:
This code is how try detect the click over some sprite:
But, not working!
Greetz...
I' am newbie with SFML and have some dudes...
I want detect click in the matrix buttons (Button = sprite, with some things changed)...
This code make the detection of mouse click on area of sprite:
Code: [Select]
bool Boton::isMouseOverBoton(float mouseX, float mouseY)
{
return (((mouseX >= this->xPos) && (mouseX <= this->xPosMax)) && ((mouseY >= this->yPos) && (mouseY <= this->yPosMax)));
}
//FunciĆ³n para evaluar si se ha clickeado sobre el boton
//Function for evaluate if has clicking over button
bool Boton::isMousePressedLeftBoton(sf::RenderWindow *ventana)
{
return (Boton::estado = Boton::isMouseOverBoton((float)ventana->GetInput().GetMouseX(), (float)ventana->GetInput().GetMouseX()) && ventana->GetInput().IsMouseButtonDown(sf::Mouse::Left));
}
This code is how try detect the click over some sprite:
Code: [Select]
if(ventana.GetInput().IsMouseButtonDown(sf::Mouse::Left))
{
for(int i=0; i<cBotones; i++)
{
for(int j=0; j<cBotones; j++)
{
if(boton[i][j].isMousePressedLeftBoton(&ventana))
{
boton[i][j].cambiarColor(sf::Color::Red);
}
}
}
}
But, not working!
Greetz...