Revert element to original position

Get help using Construct 2

Post » Fri Feb 08, 2013 5:32 am

Hi!

I'm doing a drag and drop animation. Does anyone knows if there's an event/action or condition that I can use to ensure that the draggable elements are reverted back to the original position if it is not dropped into the correct droppable area?

Thank you! :)
B
9
Posts: 44
Reputation: 570

Post » Fri Feb 08, 2013 5:54 am

When you click the item to drag it, have it store the coordinates it was at in a variable. Then when you need to revert, just set the X,Y to the coordinates in teh variable.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Fri Feb 08, 2013 8:10 am

How do i store the coordinates of the element/s at the start of the position?

Thank you! :)
B
9
Posts: 44
Reputation: 570

Post » Fri Feb 08, 2013 10:07 am

You can store them in Variables "On start of drag and drop", see global variables here:
https://www.scirra.com/manual/83/variables

or store them in the sprite itself by setting some instance variables. these are created in the properties of the sprite. See the manual here:
https://www.scirra.com/manual/73/instance-variables

Edit: Took the odd space off the links. weirdParadox2013-03-05 17:22:22
B
200
S
51
G
30
Posts: 897
Reputation: 36,496

Post » Fri Feb 08, 2013 1:48 pm

Hi,

I can't open the links. It states that the resource cannot be found.
B
9
Posts: 44
Reputation: 570

Post » Fri Feb 08, 2013 3:05 pm

For some reason there is a space as the last character of the link. When you click them, go to the address bar and delete the %20 at the end. Or Just click these ones. Also searching the manual works perfectly fine.

Variables

instance-variablesBluePhaze2013-02-08 15:07:14
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,418

Post » Tue Feb 12, 2013 7:25 am

i did the global variables, but i can't seem to get it right. I can't understand much from the links. Is it okay for you to explain in more detail?
Thank you very much :)
B
9
Posts: 44
Reputation: 570

Post » Tue Feb 12, 2013 8:30 am

[QUOTE=aisyah24] i did the global variables, but i can't seem to get it right. I can't understand much from the links. Is it okay for you to explain in more detail?
Thank you very much :)[/QUOTE]

At the event '-> On drag start' you'll need to set those global variables to position of your object:

DragStartX=Object.x
DragStartY=Object.y.

Then on event '->dragNDrop dropped':

if(not overlapping TargetObject)
.. set object.x to DragStartX
.. set object.y to dragstartY
B
24
S
8
G
7
Posts: 756
Reputation: 7,192


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 20 guests