How do I enable drag & drop after 1 second with one touch

0 favourites
  • 13 posts
From the Asset Store
320 high-quality cinematic sound effects for trailers and game scenes.
  • Hello,

    I'd like to know if there is any way of enabling drag & drop of a sprite only after touching the sprite for a certain amount of time. I tried several methods but only work with two touches and not with just one.

    What I want to accomplish is:

    1) Enable the sprite's drag & drop behavior after touching for 1 seconds the sprite.

    2) Move the sprite and drop it at the desired position without releasing it from the first touch (this is most important.)

    3) When dropped, disable drag & drop (this is easy)

    4) It shoud use Drag and Drop since move to X and Y doesn't work as expected.

    Thanks!

  • There are plenty of ways you could do this. One way (these are the sort of variables I would use, I hope my non-declaring them first doesn't make it confusing):

    If Object is not in touch

    • set boolean Object.inTouch to False
    • set Object.TimeToDrag to 0

    If Object is in touch

    • trigger once: set variable Object.TimeToDrag to time + 1.0
    • If Object.TimeToDrag < time and Object.TimeToDrag > 0

    --- Start your drag behavior (there are good examples in the tutorials, I think)...

    Hope this helps....

  • Thanks for the response!

    I did it in a similar way you say but the problem is that when the drag and drop enables after one second you have to end the touch and touch again in order to drag the object. I need a way to start the drag without untouching and touching the object again.

  • How are you dragging the object? There are plugins etc but you could just add the following code in place of my "--- Start your drag behavior...." above:

    • Trigger once: set variable Object.TouchDeltaX to: Object.X - Touch.X ; and set variable Object.TouchDeltaY to: Object.Y - Touch.Y
    • Set Object to position: X = Touch.X - Object.TouchDeltaX ; Y = Touch.Y - Object.TouchDeltaY (this will fire each tick that the object is in touch after the 1 sec delay)

    That second line can make for a jerky drag movement, so you could replace it with this, which will smooth things down:

    • Set Object.X to lerp(Object.X, Touch.X - Object.TouchDeltaX, 10*dt)
    • Set Object.X to lerp(Object.Y, Touch.Y - Object.TouchDeltaY, 10*dt)

    I think that should work... I hope I've got my minuses the right way round!

  • I think the drag is not working as the drag & drop does. While dragging if the touch leaves the object it does not move it anymore. You can see that behavior on this example I made from your suggestion, I didn't include the 1 second behavior because is the dragging having problems now. By the way, thanks for the replies!

    Example:

    [attachment=0:2lhkaoif][/attachment:2lhkaoif]

  • leotaglia, could you re-post the link, but add a gap after the http - or put it in brackets or something so it doesn't get filtered. I'll take a look at it and help if I can.

    Edit - disregard!!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here you go - try this version of you file. I removed all of the global variables. More flexible to keep them as object variables - you can then apply this technique to a family of objects without having to make things complicated.

  • I just looked at the version number of your file. I can only think of one reason why you might be using r156 (I just googled it). Please don't expect help on this forum if you're going to steal from the developers at Scirra!

  • I understand you posture and I share it. The problem is that I need to deliver multiplatform games and I'm researching different products an the only way to know if this product has what it says it does is to test the full version, which is not possible if you don't buy it. I definitely will purchase the Personal license one I make sure this product is what I need.

    Thanks for the help.

  • I understand your reticence at spending money when you don't know the prog's capabilities. As long as you're not hoping to make an advanced game for mobile then I think you'll find C2 to be excellent (IMO) as a game development tool.

  • [quote:26ikb9ji]I understand you posture and I share it. The problem is that I need to deliver multiplatform games and I'm researching different products an the only way to know if this product has what it says it does is to test the full version, which is not possible if you don't buy it. I definitely will purchase the Personal license one I make sure this product is what I need.

    Thanks for the help.

    I hope you don't steal a car first before you decide to buy it !!!!

  • [quote:2o2lzd6t]I understand you posture and I share it. The problem is that I need to deliver multiplatform games and I'm researching different products an the only way to know if this product has what it says it does is to test the full version, which is not possible if you don't buy it. I definitely will purchase the Personal license one I make sure this product is what I need.

    Thanks for the help.

    I hope you don't steal a car first before you decide to buy it !!!!

    Of course not, that's why you can get Test Drives and you get a full car on that test drive, you don't get half a car.

    cheers.

  • If you're looking to test all the functionality of our software that is available in the paid edition, drop me an email to .

    If you let me know in advance of payment, we'll permit you to purchase it and give you a refund within 10 days if you're not happy with it for any reason.

    We only offer this every now and then, and for people who ask us in advance (not all sales).

    Am locking this topic as the version being used is well out of date. Newer versions have a lot of bug fixes and it's unfair to request free time/help from our users using these older versions.

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