I am trying to figure out how to drag a sprite. I know when the mouse is being hovered, pressed, or released over a sprite. I don't know how to tell if the mouse is being pressed and moved at the same time. Every time I try to use event.type
, I only get one mouse event back (SDL_MOUSEMOTION
, SDL_MOUSEBUTTONUP
, or SDL_MOUSEBUTTONDOWN
). I tried doing something like (pseudo-code):
if(event.type == SDL_MOUSEMOTION && event.type == SDL_MOUSEBUTTONDOWN && mouse_in_sprite && left_button_pressed) {
/* Never goes in here */
}
However, it never goes inside that if statement because the event.type
is never more than one of the above mentioned every frame (unless I'm doing it wrong).
In the picture below, I am trying to make it so the scrollbar on the right moves up and down like a normal scrollbar would when pressing the left mouse button on the sprite and moving the mouse up or down.
Unfortunately, I don't know how to proceed further than getting the mouse position when the mouse is pressed on the sprite (pseudo-code):
if (mousePressed(SDL_BUTTON_LEFT)) {
currentMousePosition = getMousePosition();
/* Do something with currentMousePosition.x, currentMousePosition.y */
}
Any help would be appreciated! Thank you!