Jasper wrote:Here you go.Notes:
dragX is the X position on the sprite of where the mouse took hold of the sprite. (can you figure out what dragY is? )
As soon as the mouse clicks on the object you want to drag & drop the local boolean PickedUp is set to true, as soon as the mouse releases the button Picked Up is set to false.
First we test whether the mouse is within the area of where drag and drop-ing is allowed. If it is > we set the sprite to the Mouse.X en Mouse.Y.
If its not, we test whether the mouse is too far to the right or whether it is too far down. In the first case we set the sprites x to the furthest allowed x and set the y to Mouse.Y. Second case works like this.
Then, at last, we test if the mouse is both too far to left and and too far downwards, and we set the position of the sprite to the furthest allowed position.
If you got any questions just let me know
PS: I too late realised I could use imagepoints (I used to make games with Gamemaker which has not imagepoints ;d), so these might be handier instead of using Sprite.height/2 etc (also only works when the origin is in the middle of the image!)
Users browsing this forum: Yahoo [Bot] and 20 guests