GameMakerHelpBlog

Sunday, November 26, 2006

Drag and Drop boxes....

Hi

Well it is hard to explain but this is for draging a object with the mouse and the dropping it again.
It is NOT for Ragdoll games
It can be for other games
Remember [code]&[/code] have nothing to do with the code
[code]

//this is for create event only
Drag=false//this switches the object "on and off" basicaly
Mouse_Offset_X=0//used to calculate the offset of the mouse click to object for X
Mouse_Offset_Y=0//used to calculate the offset of the mouse click to object for Y
global.myid=id//used to grab the instance id of the object directly under mouse pointer
[/code]

[code]

//this is for end step only
with(global.myid)//with the object directly under mouse pointer
{
if(Drag=true)//if the object has been clicked (is "on")
{
x=mouse_x-Mouse_Offset_X//object's X = offset of obj.x & mouse_x
y=mouse_y-Mouse_Offset_Y//object's Y = offset of obj.y & mouse_y
}
}
[/code]
[code]

//you can change this to any mouse button (warning it is a mouse only function

with(all)//you can put whatever you want to check for in this, not just "all"
{
if(position_meeting(mouse_x,mouse_y,self))//checks for obj directly under mouse
{
global.myid=self.id;//sets the global var to the id of instance under mouse
Drag=true;// turns "Drag" on making the obj dragable by the mouse
Mouse_Offset_X=mouse_x-x;//moves object to the mouse_x possition
Mouse_Offset_Y=mouse_y-y;//moves object to the mouse_y possition
}
}
[/code]
[code]
//global.left release event
Drag=false
[/code]

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home