Is there a way to limit drag and drop when panning

0 favourites
  • 6 posts
From the Asset Store
320 high-quality cinematic sound effects for trailers and game scenes.
  • 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?

  • You could clamp your draggable object to a center point.

    dl.dropboxusercontent.com/u/139218609/examples/clamp.capx

  • wouldn't it be a better idea to drag the camera instead of the image?

  • 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)

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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).

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)