When using drag and drop, how do I make an object snap/drop to a precise point?

0 favourites
  • 7 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • I am creating a prize platform and have included 4 images of each prize which have been inserted as 1 tiled background. This then tweens onto the screen at the click of a button. As you can see from the image, I have a sort-of 'window' where the images can be viewed on the screen but at the moment the tiled background can be dragged and dropped anywhere on a horizontal axis which means you can see part of one image and part of another which is no good.

    I need the tiled background to drop/snap to a certain point each time so that one image is aligned perfectly in the window, can any help? Is it possible to do this as one tiled background or do I need to separate into 4 separate ones?

    For reference, the tiled background is 2840 x 440, meaning each image is 710 x 440.

  • You can use round() expression to snap to grid. For example:

    Sprite On Drop : Sprite set X to clamp(round(self.x/100)*100, 300, 700)

    This will snap the sprite between X 300 and 700, at 100px intervals.

    Another option is to put invisible placeholder objects to where you want pictures to be placed. In "On Drop" event pick the nearest placeholder and set the sprite to its position.

  • Thanks dop, really appreciate your help. I've tried using the round() expression and tweaked the numbers in it but can't get it to snap at the correct points no matter what I put, any ideas what the exact ones would be based on the dimensions given in my first post?

    I also tried putting in 3 small 4 x 4 sprites and pinned to the corner of each image, how do I get it to pick the nearest one? Essentially, what I need to do is get the corner of each image to set X to 20 when dropped as that's where my 'window' starts.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • any ideas what the exact ones would be based on the dimensions given in my first post?

    Sorry, I don't quite understand your setup.

    I also tried putting in 3 small 4 x 4 sprites and pinned to the corner of each image, how do I get it to pick the nearest one?

    Use "Pick nearest" condition.

    Image On Drop
    Placeholder pick nearest to (Image.x, Image.y)
    .........Image set position to Placeholder
    
  • I've tried doing this along with a number of other possibilities but nothing seems to work :(

    I've attached an image of what you suggested but when dropping, it only drops to its' starting position.

    In my head, I've done everything right - selected on drop, pick nearest placeholder to image point (corner of window) and set position of image to placeholder but not getting anywhere.

    Can you see anything in my method that looks incorrect?

  • You drop PRImage object, but you are picking a placeholder nearest to a different object - PrizeDetails. You probably need to pick nearest to PRImage.

  • I tried picking it nearest to RPImage but that didn't work.

    I'll keep trying things as I'm sure your method will work - I've just got to find the right way.

    Thanks a lot for your help!

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