Another good article on something like that is this --
http://www.mactech.com/articles/mactech/Vol.12/12.08/
GXRigidBodyDragging/index.html
Here's one of my test SWFs by the way, so you can see what I'm talking
about:
http://hosted.zeh.com.br/misc/novo2.swf
looks great!
i thought that topic is dead for me. but maybe i give a triy again :)
zeh, would you share the code of your test swf?
It's a bit old (should be some kind of class now) but here it is:
Math.decToRad = function (graus) {
return (graus * (Math.PI/180));
}
ASSetPropFlags(Math, "decToRad", 1, 1);
Math.radToDec = function (radianos) {
return (radianos / (Math.PI/180));
}
ASSetPropFlags(Math, "radToDec", 1, 1);
MovieClip.prototype.makeDraggable = function() {
this.onPress = function() {
this.lastMouseX = this._parent._xmouse;
this.lastMouseY = this._parent._ymouse;
this.onMouseMove = function() {
this.deltaX = this._parent._xmouse - this.lastMouseX;
this.deltaY = this._parent._ymouse - this.lastMouseY;
this.delta = Math.sqrt((this.deltaX*this.deltaX) +
(this.deltaY*this.deltaY));
this.radiusX = this.lastMouseX - this._x;
this.radiusY = this.lastMouseY - this._y;
this.radius = Math.sqrt((this.radiusX*this.radiusX) +
(this.radiusY*this.radiusY));
this.dragAngle = Math.atan2(this.deltaX, this.deltaY) -
Math.atan2(this.radiusX, this.radiusY);
this.rotationAngleSin = this.delta * Math.sin(this.dragAngle) /
this.radius;
this._x += this.deltaX;
this._y += this.deltaY;
var p1 = {x:this._xmouse, y:this._ymouse};
var p2 = {x:this._xmouse, y:this._ymouse};
this.localToGlobal(p1);
this._rotation -= Math.radToDec(Math.asin(this.rotationAngleSin)) *
(this.radius/25);
this.localToGlobal(p2);
this._x -= p2.x-p1.x;
this._y -= p2.y-p1.y;
this.lastMouseX = this._parent._xmouse;
this.lastMouseY = this._parent._ymouse;
updateAfterEvent();
};
this.onMouseMove();
};
this.onMouseUp = function() {
delete this.onMouseMove;
};
};
Then to apply:
myMC.makeDraggable();
This is a literal remake of the equations mentioned on that article I've
linked above (I even used similar variable names). It isn't perfect, though;
you'll notice, for instance, that dragging an object by its center will make
it rotate more than it normally should (as if the whole thing was
lightweight). Probably some kind of strength based on the drag radius should
be applied to the rotation force.
It did work perfect for what I needed, though (I just had to drag objects
from a few special corners).
I know Yugo Nakamura has made something similar a loooong time ago (Flash 4)
and it worked great, with inertia and all, but I guess the logics behind his
one were a bit different.
- Zeh
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com