e309xerz0wpw
Member
GML:
#event create
additionaloffsetx = 0;
additionaloffsety = 0;
#event step
if mouse_check_button_pressed(mb_left) and position_meeting(mouse_x, mouse_y, id)
{
tracking = 1;
if mouse_x != x and mouse_y != y
{
var offsetxx = -(x-mouse_x);
var offsetyy = -(y-mouse_y);
sprite_set_offset(sprite_index, offsetxx+additionaloffsetx, offsetyy+additionaloffsety);
additionaloffsetx = offsetxx;
additionaloffsety = offsetyy;
}
}
if mouse_check_button_released(mb_left) and tracking = 1
{
tracking = 0;
}
if tracking = 1
{
x = mouse_x;
y = mouse_y;
}
im trying 2 make a draggable object
u click, it sets the origin of the sprite where u clicked within the image itself, then follows ur cursor, when u release, it ends where it is
u click again, it accounts 4 the previous offset, sets the new offset, follows ur cursor, releasing ends it
u click again, it is not setting the new offset correctly
i would like 2 know y this isnt working, &/or how precisely sprite_set_offset works, bc it appears 2 not compound the offset naturally, it is setting the offset based on the sprites original sprite origin, not off the new offset, but im failing 2 account 4 this w my above code but i genuinely cant figure out y, thx 4 help
EDIT: accidentally wrote additionaloffsety - 0; instead of additionaloffsety = 0;, bc the code im asking 4 help w/ uses the latter