Drag and Rotate  
Author Message
animee





PostPosted: 2006-8-9 21:58:40 Top

flash-actionscript, Drag and Rotate Hi all,

i'm working on a projekt, which is a card game and i need to implement some
kind of rotation function.
Actually i can drag, pick up and drop the cards.

Now i want the cards to rotate depending on the movement of the users mouse
when he drags a card.
I tried to do it on my own but i can't figure it out.

As an example of what i mean check this link please:
http://www.thibaud.be/

I don't need a complete solution but an advice or a link to a tutorial that
deals with this kind of problem would be very nice.

Thank you very much.

 
kglad





PostPosted: 2006-8-9 22:40:00 Top

flash-actionscript >> Drag and Rotate when you initiate a startDrag() you can also initiate a loop that eases the _rotation property into an amount that's proportional to the mouse speed.
 
animee





PostPosted: 2006-8-9 22:47:00 Top

flash-actionscript >> Drag and Rotate Hi kglad
thanks for the quick reply.

I know but the problem is that the clip rotates around its registration point
but i want it roate around that point the users clicked to start the dragging.
Know what i mean?

 
 
kglad





PostPosted: 2006-8-9 23:50:00 Top

flash-actionscript >> Drag and Rotate open flash, create a new actionscript file and paste the code that's below the
dotted line into the as file and save as regPoint.as in the same directory as
your project files.

in your project fla attach the following to a frame

#include "regPoint.as"


you can now set and get some additional properties of movieclips. for
example, you can "change" the registration point of any movieclip mc1 by using:

mc1._xreg=_root._xmouse; // setting mc1's registration point to be the mouse
(in your situation, when mc1 undergoes a startDrag()
mc1._yreg=_root._ymouse;

and you can then use the new _rotation2 property of mc1 (mc1._rotation2) to
change mc1's _rotation relative to this new registration point.


 
 
kglad





PostPosted: 2006-8-9 23:52:00 Top

flash-actionscript >> Drag and Rotate -----------------------------

var MCP = MovieClip.prototype;
MCP._xreg = MCP._yreg=0;
MCP.setPropRel = function(prop, amount) {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
this[prop] = amount;
var b = {x:this._xreg, y:this._yreg};
this.localToGlobal(b);
this._parent.globalToLocal(b);
this._x -= b.x-a.x;
this._y -= b.y-a.y;
};
MCP.set_x2 = function(v) {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
this._x += v-a.x;
};
MCP.get_x2 = function() {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
return a.x;
};
MCP.set_y2 = function(v) {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
this._y += v-a.y;
};
MCP.get_y2 = function() {
var a = {x:this._xreg, y:this._yreg};
this.localToGlobal(a);
this._parent.globalToLocal(a);
return a.y;
};
MCP.set_xscale2 = function(v) {
this.setPropRel("_xscale", v);
};
MCP.get_xscale2 = function() {
return this._xscale;
};
MCP.set_yscale2 = function(v) {
this.setPropRel("_yscale", v);
};
MCP.get_yscale2 = function() {
return this._yscale;
};
MCP.set_rotation2 = function(v) {
this.setPropRel("_rotation", v);
};
MCP.get_rotation2 = function() {
return this._rotation;
};
MCP.get_xmouse2 = function() {
return this._xmouse-this._xreg;
};
MCP.get_ymouse2 = function() {
return this._ymouse-this._yreg;
};
with (MCP) {
addProperty("_x2", get_x2, set_x2);
addProperty("_y2", get_y2, set_y2);
addProperty("_xscale2", get_xscale2, set_xscale2);
addProperty("_yscale2", get_yscale2, set_yscale2);
addProperty("_rotation2", get_rotation2, set_rotation2);
addProperty("_xmouse2", get_xmouse2, null);
addProperty("_ymouse2", get_ymouse2, null);
}
ASSetPropFlags(MCP, null, 1);
delete MCP;

 
 
animee





PostPosted: 2006-8-10 0:23:00 Top

flash-actionscript >> Drag and Rotate Wow!
This is amazing - Exactly what i was looking for.
Thank you very much - You saved my day =).
 
 
kglad





PostPosted: 2006-8-10 0:56:00 Top

flash-actionscript >> Drag and Rotate you're welcome. the regPoint.as file is someone elses coding, but i don't remember who.