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

Get help using Construct 2

Post » Fri Apr 18, 2014 6:26 pm

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!
B
5
S
1
Posts: 28
Reputation: 433

Post » Fri Apr 18, 2014 10:10 pm

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....
Last edited by Colludium on Sat Apr 19, 2014 12:07 am, edited 1 time in total.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Fri Apr 18, 2014 10:17 pm

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.
B
5
S
1
Posts: 28
Reputation: 433

Post » Fri Apr 18, 2014 10:49 pm

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!
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Fri Apr 18, 2014 11:59 pm

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:
dragtest.capx
B
5
S
1
Posts: 28
Reputation: 433

Post » Sat Apr 19, 2014 12:01 am

@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!!
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Sat Apr 19, 2014 12:12 am

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.
You do not have the required permissions to view the files attached to this post.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Sat Apr 19, 2014 12:21 am

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!
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Post » Sat Apr 19, 2014 12:18 pm

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.
B
5
S
1
Posts: 28
Reputation: 433

Post » Sat Apr 19, 2014 1:28 pm

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.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,230
Reputation: 44,892

Next

Return to How do I....?

Who is online

Users browsing this forum: Artcadev and 50 guests