Copy link to clipboard
Copied
Hi,
I have 6 pieces and 6 targets and i was wondering how do i make the pieces return to its orginal x and y axis when the piece is put into the wrong target.
The instance names for the pieces are: piece1_mc piece 2_mc etc.
The target names are: target1_mc target2_mc etc.
Copy link to clipboard
Copied
It would take a bit of time to write out all of the code, but here is the approach I would take:
Instead of placing the objects somewhere and then using some technique to know when they are in the right place, put them in their right place.
When you enter that screen, have each object store its own location, and programmatically move it to the start point. That might be a random location, or some other rule that lays them out neatly. Store that position too.
As the user drags the object, use Pythagoras to calculate the distance from the stored right place location.
If the distance is less than a certain tolerance, use a tween to move the object to the right place location, in a short amount of time.
If the distance is more than a certain tolerance, use a tween to move the object back to its stored start location, taking more time.
Both ActionScript and CreateJS have tween libraries built into them.