Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
mittererr

Rotation with transformAroundPoint - position drift?

Recommended Posts

Hi,

 

I'm rotating a textfield using transformAroundPoint. The rotation is initiated by a MouseEvent.MOVE. When I move the mouse arround for some time the textfield position drifts more and more away.

 

My Source Code:

private function btnRotateMouseMove(evt : MouseEvent) : void {
var mousePos : Point = new Point(this.stage.mouseX, this.stage.mouseY);
var origin : Point = _textobj.localToGlobal(_textobj.__origin);
var beta : Number = 180 * Math.atan((mousePos.y - origin.y) / (mousePos.x - origin.x)) / Math.PI;

TweenLite.to(_textobj.__textField, 0, {transformAroundPoint:{point: _textobj.__origin, rotation:beta}});
}

 

Is there any Solution?

 

Thank You

Link to comment
Share on other sites

Are you changing _textobj.__origin often? If it is consistent, there shouldn't be any drifting. Please send a simple FLA demonstrating the issue if you're still running into trouble. The transformAroundPoint plugin runs code with localToGlobal() and globalToLocal() to ensure that the point remains exactly matched up with where it should be. I believe there is a bug in Adobe's Flex framework, though, that can cause those methods to return incorrect data if your object has an outline. Are you using Flex?

Link to comment
Share on other sites

Yes I'm using Flex SDK 4.1.0.16076. It looks like a kind of inaccuracy?

 

_textobj.__origin is only set one time, while generating the instance.

 

Is it possible that there are problems rotating a textfield?

Link to comment
Share on other sites

Nope, I'm not aware of any issues with rotating TextFields. Does your object (or its container(s)) have an outline in Flex? If so, you're almost surely running into the Flex bug. Again, it would be REALLY helpful if you posted a super-simple demo of the issue (a Flex project zip or fxp is fine). It's tough to troubleshoot blind.

Link to comment
Share on other sites

Here is a Flashproject for testing . . .

Link to comment
Share on other sites

Yeah, this is caused by a buildup of tiny lacks in precision in Flash's reporting of localToGlobal() and globalToLocal() - there is no easy fix in terms of the plugin. You're definitely using TweenLite/TransformAroundPoint in a very unconventional way - I'd recommend doing the math manually instead of relying on a tweening engine (you're not tweening after all). Like:

 

var parentOrigin:Point = this.gobalToLocal(_textobj.localToGlobal(_textobj.__origin)); //origin's position in parent - set this in your MOUSE_DOWN handler
function btnRotateMouseMove(evt : MouseEvent) : void {
   var mousePos : Point = new Point(this.stage.mouseX, this.stage.mouseY);
   var origin : Point = _textobj.localToGlobal(_textobj.__origin);
   _textobj.rotation = 180 * Math.atan((mousePos.y - origin.y) / (mousePos.x - origin.x)) / Math.PI;

   var p:Point = this.globalToLocal(_textobj.localToGlobal(_textobj.__origin));		
   _textobj.x += parentOrigin.x - p.x;
   _textobj.y += parentOrigin.y - p.y;
}

Link to comment
Share on other sites

Thank you very much. I solved it by setting a new registration point by hand.

 

Anyway - Greensock rocks!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×