Hi guys, I'm trying to make it so that when the user clicks on a sprite it runs a function. However, everytime I click it runs the function a couple of hundred times...
I've tried a lot of thing such as making booleans that become false on every loop or or using SDL_GetTicks() to try to control the time but nothing seems to be working...
Someone help please?
Here is my code.
1 2 3 4 5 6 7 8 9 10 11 12 13
if (heart->CheckBounds(mousePosX, mousePosY))//checks whether mouse is over sprite
{
if (events->type == SDL_MOUSEBUTTONDOWN)
{
if (events->button.button == SDL_BUTTON_LEFT)
{
Character_Visual->CCreation_Add_HP();
//the above function executes about a hundred times
}
}
}
If i remember correctly SDL will send\trigger that event time in your loop when the button is down. the thing is you could loop through 1000 times int the time(0.1sec) it takes you to release the button.
try using SDL_MOUSEBUTTONUP so you trigger on release. this gets fired just once