Share Posted March 1, 2011 I am trying to round off rotations to the neatest 90 degrees and then scale the transform items to fit to the left or right side of the stage. I know how to round off the rotations, but I can't seem to get the positioning and the scaling right (because the x and y values change after the rotation). Here is the code I am using:P private function rotateAroundCenter (ob:*, angleDegrees:Number, ptRotationPoint:Point):void { var m:Matrix=ob.transform.matrix; m.tx -= ptRotationPoint.x; m.ty -= ptRotationPoint.y; m.rotate (angleDegrees*(Math.PI/180)); m.tx += ptRotationPoint.x; m.ty += ptRotationPoint.y; ob.transform.matrix=m; } private function scaleToFit($side) { var itemAbsRotation:Number = Math.abs(tItem.targetObject.rotation); var rotateNum:Number = 0; var ptRotation:Point = new Point(_currRollOver.width/2, _currRollOver.height/2); if(itemAbsRotation > 0 && itemAbsRotation < 135) { rotateNum = roundToNearest(90, itemAbsRotation); }else if(itemAbsRotation > 134 && itemAbsRotation < 213) { rotateNum = roundToNearest(180, itemAbsRotation); }else if(itemAbsRotation > 213 && itemAbsRotation < 45) { rotateNum = 0; } rotateAroundCenter(_currRollOver.targetObject, rotateNum,ptRotation); if(imgInfo.type == "COLOR") { pX = _mainAppStage.x; pY = _mainAppStage.y; if($which == "left") { _currRollOver.width = _mainAppStage.width/2; _currRollOver.height = _mainAppStage.height; _currRollOver.x = pX; _currRollOver.y = pY; }else if($which == "right") { _currRollOver.width = _mainAppStage.width/2; _currRollOver.height = _mainAppStage.height; if(mirrorOffset == false) { _currRollOver.x = _mainAppStage.width/2 + _currRollOver.width/2 + 2; _currRollOver.y = _mainAppStage.y; }else { _currRollOver.x = _mainAppStage.width + _currRollOver.width/2; _currRollOver.y = _mainAppStage.y; } } } Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now