Groups | Blog | Home
all groups > flash actionscript > august 2006 >

flash actionscript : Help with dragging and rotation


supasuka
8/19/2006 3:39:38 PM
Hi all,
I have the problem that i want a square to have an angular movement when i
drag it.
I have found a script that comes very close to it but the angualr movement
only apears when releasing the clip.
I tried hard to get it working the way i want it but I fail. =(

I'm more a designer than a coder so i hope someone here could give me an
advice or tip how i can do this.
Or maybe a link to a tutorial covering this topic?

That's the script:



Thank you very much


damp = .8;
bar.onPress = function() {
bar.onEnterFrame = undefined;
bar.vr = 0;
bar.vx = 0;
bar.vy = 0;
downX = _xmouse;
downY = _ymouse;
onEnterFrame = makeVector;
};
bar.onRelease = bar.onReleaseOutside=function () {
findVector();
bar.onEnterFrame = barMove;
onEnterFrame = undefined;
clear();
};
function makeVector() {
clear();
lineStyle(1, 0, 100);
moveTo(downX, downY);
lineTo(_xmouse, _ymouse);
dx = _xmouse-downX;
dy = _ymouse-downY;
}
function findVector() {
vectorAngle = Math.atan2(dy, dx);
vectorMag = Math.sqrt(dx*dx+dy*dy);
vectorX = downX-bar._x;
vectorY = downY-bar._y;
vectorDist = Math.sqrt(vectorX*vectorX+vectorY*vectorY);
barAngle = Math.atan2(vectorY, vectorX);
resultAngle = vectorAngle-barAngle;
bar.vr = Math.sin(resultAngle)*vectorMag*vectorDist/65;
bar.vx += dx*.5;
bar.vy += dy*.5;
}
function barMove() {
this.vx *= damp;
this.vy *= damp;
this.vr *= damp;
this._x += this.vx;
this._y += this.vy;
this._rotation += this.vr;
bounds = this.getBounds(_root);
if (bounds.xMin<20) {
this._x += 20-bounds.xMin;
this.vx *= -1;
} else if (bounds.xMax>520) {
this._x += 520-bounds.xMax;
this.vx *= -1;
}
if (bounds.yMin<20) {
this._y += 20-bounds.yMin;
this.vy *= -1;
} else if (bounds.yMax>380) {
this._y += 380-bounds.yMax;
this.vy *= -1;
}
}
kglad
8/19/2006 5:24:25 PM
supasuka
8/19/2006 5:46:55 PM
Yes,
im searching for a solution to simulate angular movement for such a long time and this is the only workaround i could find.
kglad
8/19/2006 7:14:11 PM
that code causes changes to the _rotation property of bar, but other than that
it has nothing to do with the issue you posed.

in what manner do you want the _rotation property of your dragged movieclip to
change as it's being dragged? do you want it to change randomly or is there
some method/effect that you want to apply to the _rotation?
supasuka
8/19/2006 8:35:52 PM
Im looking for a kind of effect like this.

http://www.intentionallies.co.jp

I still implemented the "throwing around" and "bouncing of the wall" of my
clip but i can't figure out how the rotation of the cards has to be done.
I thought the code snippet i found would lead in the right direction.

Would be nice if you point me in the right direction. =)
kglad
8/19/2006 8:44:11 PM
movieclips will rotate about their registration point when you set their
_rotation property.

in the example you cited, the movieclips rotate about the mouse's position.
if that's what you want you should search this forum for another thread where
the poster cited the same website asking for help.

i supplied that poster with code to "change" the registration point so they
could create the same effect as displayed on that site.
AddThis Social Bookmark Button