Is there a way to limit drag and drop when panning

Get help using Construct 2

Post » Fri Jan 17, 2014 8:20 pm

Hi,

I cannot find an answer to this problem anywhere.

Basically I have an image larger than the viewport and I want to be able to pan around the image looking for clues in a

game. I have enabled drag and drop & touch for use on tablets etc.

Anyway, the problem is that the image can be dragged completely off screen so I want it to be limited to the edge of

the window.

Using Bound to Layout would work if I could set the window to the centre of the layout. The problem here is that it can

only be dragged right and down and not up and left.

Using sprites as collision objects outside of the viewing area kind of works if the collision causes the image to

"drop". But it is then possible to drag again and go over the edge of the screen.

So is there a way to set absolute limits for drag and drop? or a way to move the window to the centre of the layout

and use Bound to Layout? Or am I missing something very obvious?


B
4
Posts: 8
Reputation: 237

Post » Fri Jan 17, 2014 9:15 pm

You could clamp your draggable object to a center point.
https://dl.dropboxusercontent.com/u/139218609/examples/clamp.capx

B
10
S
2
G
1
Posts: 202
Reputation: 1,555

Post » Fri Jan 17, 2014 9:29 pm

wouldn't it be a better idea to drag the camera instead of the image?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 17, 2014 9:47 pm

Another option:
You could put an invisible sprite on your layout, give it "scroll to" behaviour, and on each touch set its position to touch x,y

This would effectively move the portview center towards where you clicked.
Eliminating the need for drag and drop.

(you could add some movement to the invisible sprite to smoothen the camera transition)
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Sat Jan 18, 2014 8:56 am

Thanks everybody for your suggestions, all very helpful.

The clamp method looks like exactly what I was looking for, I'll give it a go later.

I am intrigued by the "drag the camera" idea though, how do you do that?
B
4
Posts: 8
Reputation: 237

Post » Sun Jan 19, 2014 3:33 am

@ianp , @LittleStain 's method would be better suited in a situation where your background isn't a static image. In an example situation, maybe you have moving sprites on your background. When you go to drag it you would then have to pin all those moving objects and unpin them on drop...

Solution is to make a camera sprite with the drag/drop behavior instead of a background, give it a scroll to behavior, and use clamp again to prevent the camera from leaving the layout(if a simple bound to layout isn't enough).


B
10
S
2
G
1
Posts: 202
Reputation: 1,555


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests