Drag and drop - limit screen area

Get help using Construct 2

Post » Sat Jan 26, 2013 7:23 pm

Hi all,

I have an object that I can drag around the screen. I have set its behavior to be bound to the layout and that stops it leaving which is great. My issue is part of my layout contains a hud and I wanted the same kind of restriction to stop it being dragged over that.

I have tried putting a transparent sprite there as a wall and playing with various different parameters but that doesn't seem to help. Any pointers would be amazing.

Thanks
B
14
S
2
Posts: 5
Reputation: 1,290

Post » Sat Jan 26, 2013 8:36 pm

Replace the drag and drop behaviour by your own events.

I'm creating an example for you right now so I don't have to explain it, hold on a minute
B
13
S
3
G
4
Posts: 35
Reputation: 3,358

Post » Sat Jan 26, 2013 9:14 pm

Here you go.
https://dl.dropbox.com/u/87237423/D%26D.capx

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!)
B
13
S
3
G
4
Posts: 35
Reputation: 3,358

Post » Sun Jan 27, 2013 5:16 pm

Thanks Jasper I really appreciate the effort you went to there! I'll have a go through your example and take it from there. *thumbs up*
B
14
S
2
Posts: 5
Reputation: 1,290

Post » Thu Nov 06, 2014 10:08 pm

Message: ajmaganito is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
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!)


hey jasper, i can't download your example. please give me a link again please! thanks soooo much!
B
5
Posts: 2
Reputation: 234

Post » Tue Jun 02, 2015 6:51 am

So on my application, I was able to use drag and drop pretty easily (build 206) to accomplish what I needed. In order to keep the sprite on page (my sprite size is 4000,647), all I did was add two events in my event sheet.

1) Check if it's past the X axis (upper limit), if so just set it to the appropriate X value
example: if X > 1983, set X to 1983
2) Check if it's past the X axis (lower limit), if so just set it to the appropriate X value
example: if X < -53, set X to -53

This will block the user from scrolling my sprite past it's image limits and keep it bound to my 1920,1080 layout.
B
5
Posts: 1
Reputation: 252

Post » Wed May 11, 2016 1:26 pm

;) it's work so fine...

(Object) is > x coordonate(ex 32): (Object) set x coordonate(ex 32)(

same for Y

the object stay in another object with this simple solution
B
9
S
1
Posts: 26
Reputation: 1,907


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 20 guests