Dragging y axis of an object with the mouse / Fake SMS page

S

SouchieeBlanc

Guest
Hello !
I'm making a find phone game and, actually, i'm doing the SMS system.
Anyone know how to make the scroll system?
I tried with something like:
When you click:
sprite_set_offset(my_sprite,0, mouse_y);
and after:
y = mouse_y; <-- when held down

This solution only works at the first click, because once you click again, since the origin is different, its y-axis moves back into the room with respect to its new origin and thus no longer scroll to the place where I click but higher.
Someone would have a solution so that, when I click at a y of my object and that I remain pressed, I can go up and down this object, several times, as if we were on a page of SMS / mail?
I see some tuto to drag an object, but in my case, the drag need to be in the point where i click, and i didn't found this...
Thank you in advance.
 

TheouAegis

Member
Instead of changing the y-axis, why not just store the mouse's position or relative distance in a variable and add that variable to the y coordinate?

Typically you do not want to mess with any resource properties once the resource has been made.
 
Why not grab the current mouse y position when you first click, then either continuously grab the mouse position as an end position and get the different (or do it only after mouse release) ?

Code:
if(mouse_check_button_pressed(mb_left)) {
    y_start_drag = mouse_y;
}

if(mouse_check_button(mb_left)) {
    y_stop_drag = mouse_y;
    distance = y_start_drag - y_stop_drag;
}
You can fool around with it here: Yal.cc

* edit: I added a scroll_y variable that will return either 1, 0, -1 so you could scroll the content based on that if you wanted.
 
S

SouchieeBlanc

Guest
Ty for your answer, i tried this:

In a step event:
if (mouse_check_button(mb_left))
{
y = y + mouse_y //If i put the addition in a var or "my = mouse_y and y = y+my", nothing happenso i do the sum after the =
}

but when i click, it do the addition all the step, so my object just run on the bottom :/
 
Last edited by a moderator:
S

SouchieeBlanc

Guest
I tried, the draw code give me something good, but my object wont move :(
 
S

SouchieeBlanc

Guest
ok, mb, i miss to write
y = distance. It work, but i got the same problem, when i redo a click, the object position is reset :/
 
Try this one out (I am leaving work so I through in a few comments)... Yal.cc

Basically you want to move the Y position of your object by the distance between the start and stop of the mouse_y. I added in some checks quickly (they aren't nice) so that if you stop dragging but still are clicking you dont need to go back in the other direction to do whatever... if you don't like the direction (down is up...) then you can mutliple distance by -1.

Code:
distance *= -1;
and it will transform the negative into a positive number, and vise versa.
 
S

SouchieeBlanc

Guest
Thank you very much !!
I just add 3lines code and it exactly what I wanted !
Thank you for your help !
 
Top