Okej guys, i want to make my first 2d game and i downloaded SDL 2.0. So, i didnt work with SDL so i cant get it rly. I created windows, rendering, i putted one background pict and button and i have problem with button now. so.. dont pay attention on csdl_setup->begin and end, its not important. MouseX and MouseY r my mouse cordinate in window and leftButtonMinX and others three leftbuttons are my cordinate of button picture and that is not important tho. The important thing and when is errror is "if" loop with those SDL_. When i click with my left click on my button, its always doing 20+ and he is going rly fast(bob, that button is left arrow so when i click left arrow bob will go left 20piksels). I just want that if i click once, i want to do it just once(to go +20) and that's it, or when i released my mouse button to do that one thing(to move bob 20+ and stop) and wait for another click to do another move... In this case when i click he will just do that loop and he will not stop. it will be like +20+20+20+20....... with very,very fast speed until i quit program.
Code:
void CMainClass::GameLoop(void)
{
while (!quit && csdl_setup->GetMainEvent()->type != SDL_QUIT)
{
csdl_setup->Begin();
SDL_GetMouseState(&MouseX,&MouseY);
grass->Draw();
bob->Draw();
leftButton->Draw();
if(csdl_setup->GetMainEvent()->type == SDL_MOUSEBUTTONDOWN)
{
if(csdl_setup->GetMainEvent()->button.button == SDL_BUTTON_LEFT )
{
if ((MouseX > leftButtonMinX && MouseX < leftButtonMaxX ) && (MouseY > leftButtonMinY && MouseY < leftButtonMaxY ) )
{
bob->SetX( bob->GetX() +20 );
}
}
}
csdl_setup->End();
}
}