Thread: Problem with SDL, MOUSE CLICK ON BUTTON.. c++

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    5

    Problem with SDL, MOUSE CLICK ON BUTTON.. c++

    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();
        }
        
    }
    Last edited by Kova; 02-21-2015 at 06:23 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Forms - Button Click
    By gavra in forum C# Programming
    Replies: 1
    Last Post: 11-17-2009, 01:13 AM
  2. Button click out of WM_COMMAND
    By Sober in forum Windows Programming
    Replies: 8
    Last Post: 05-03-2007, 09:07 PM
  3. button click
    By Stringer in forum C++ Programming
    Replies: 20
    Last Post: 10-17-2006, 07:00 AM
  4. Using mouse click
    By kakashi in forum C++ Programming
    Replies: 10
    Last Post: 01-31-2006, 01:38 AM