You are not logged in.
Pages: 1
Sometimes when testing stuff I need to move objects around that dont normally move. I always wished I could just drag them like a window so I made this script you can just drop at the step event.
/// drag_and_drop([button?])
//
// Enables the object to be drag and dropped with the mouse around the room.
//
// button? Optional. Can be enabled if the sprite works as a button.
// ie. contains 2 images of a button being pressed.
//
/// GMLscripts.com/license
{
var xx, yy, isbutton, hold, pressed, released;
// Implement global vars
if !variable_global_exists("cursor_dnd")
{
global.cursor_hover = noone;
global.cursor_dnd = noone;
global.cursor_xoffset = 0;
global.cursor_yoffset = 0;
}
// variables
xx = mouse_x;
yy = mouse_y;
isbutton = false;
if(argument_count>0) isbutton = argument[0];
if isbutton image_speed = 0;
// inputs
hold = mouse_check_button(mb_left);
pressed = mouse_check_button_pressed(mb_left);
released = mouse_check_button_released(mb_left);
// mark as hover instance
if position_meeting(xx, yy, id) && !instance_exists(global.cursor_hover)
{
global.cursor_hover = id;
}
if(global.cursor_hover == id)
{
if(!position_meeting(xx, yy, id))
global.cursor_hover = noone;
}
// detect click
if position_meeting(xx, yy, id) && pressed && !instance_exists(global.cursor_dnd)
{
global.cursor_dnd = id;
global.cursor_xoffset = x-xx;
global.cursor_yoffset = yy-y;
}
// dragging
if(global.cursor_dnd == id)
{
x = xx+global.cursor_xoffset;
y = yy-global.cursor_yoffset;
if isbutton image_index = 1;
if released
{
global.cursor_dnd = noone;
if isbutton image_index = 0;
}
}
}
I'm somewhat surprised this doesn't already exist here. Perhaps someone else has submitted something like this in the past but it was never added.
Right? I`ve actually wondered why the scripts have not been updated in so long!
Does this work for rotated sprites?
Hi, this is a self explanatory script. Takes 2 list data strucutures and returns 1. Thanks.
/// ds_list_merge(a,b);
//
// Returns a list with values from both lists. Will always destroy list a
//
// a list, to be destroyed
// b list, to be returned
//
//
/// GMLscripts.com/license
{
var a,b;
a = argument0;
b = argument1;
if !ds_exists(a,ds_type_list) && !ds_exists(b,ds_type_list)
return b;
else if ds_exists(a,ds_type_list) && !ds_exists(b,ds_type_list)
return a;
else if !ds_exists(a,ds_type_list) && ds_exists(b,ds_type_list)
return b;
else
{
for( var i = 0; i < ds_list_size( a ); i++ )
{
ds_list_add( b, ds_list_find_value( a, i ));
}
ds_list_destroy(a);
return b;
}
}
Pages: 1