View Full Version : dropping an object and making it feel "magnetic"?
j_scholes
06-21-2008, 10:47 AM
Anyone got any quick advice or where i can get a resource on the best way to make an object feel as if it drops like a magnet on top of another object?
thanks.
theclincher
06-24-2008, 12:40 AM
I'm trying to conceptualize this.
Would this be similar to a jigsaw puzzle game where if the user drags and drops a piece over the correct region, then that piece snaps into the appropriate, perfect x and y coordinates?
Pedal-kid
06-29-2008, 09:36 PM
make a movieclip, give it a instance name "circle" paste this code in the frame:
circle.onPress = function() {
startDrag(this);
}
circle.onRelease = circle.onReleaseOutside = function () {
stopDrag();
}
circle.initialX = circle._x;
circle.initialY = circle._y;
circle.onMouseDown = function() {
mousePressed = true;
}
circle.onMouseUp = function() {
mousePressed = false;
}
circle.onEnterFrame = function() {
if (mousePressed == false) {
this._x -= (this._x - this.initialX) / 10;
this._y -= (this._y - this.initialY) / 10;
}
}
theclincher
07-03-2008, 12:36 AM
Why don't you get the center of the display object being dragged and the center of the destination point. Find the distance between them and check if it meets a minimum distance. If it does, script it to drop in place. If you need an example FLA, just reply back and I'll be more than happy to post something up here.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.