Jump to content
Search Community

rotateSelection [SOLVED]

wsvdmeer test
Moderator Tag

Recommended Posts

Hi Jack,

 

I'm having a problem rotating a selected item when i use the following code.

How can i get the rotation right? ( is suck at math :P).

 

private function rotateSelected(value:Number) {	

      //value = -1 or 1

    var angle:Number = Math.atan2(currentTarget.x,currentTarget.y)

    manager.rotateSelection(angle+value)

}

Link to comment
Share on other sites

Hey Jack sorry for my confusing explenation,

 

post-323-133151999615_thumb.png

 

I have a transformItem on the stage and 2 buttons one for rotating the object left( - ) and one for rotating the object right( + ).

When i push one of the buttons the function rotateSelected is fired and i get a variable called "value"

 

Button "Left" gives a value of -1 wich indicates that the transformItem has to rotate counter clockwise.

Button "Right" gives a value of 1 wich indicates that the transformItem has to rotate clockwise.

 

In short i want the user to rotate the object with the buttons.

 

I know this is possible by calling TransformManager.rotateSelected("angle")

 

But i have no idea on how to get the right value for the angle.

Link to comment
Share on other sites

It should be relatively straightforward as long as you realize that rotateSelection() accepts RADIAN values, not degrees :)

 

If you want to translate degrees to radians, you'd just do:

 

var radians:Number = degrees * (Math.PI / 180);

 

So if you want it to rotate 5 degrees, have your + button call a function like:

 

function onClickPlus($e:MouseEvent):void {
   myManager.rotateSelection(5 * (Math.PI / 180));
}

 

And your - button could call something like:

 

function onClickMinus($e:MouseEvent):void {
   myManager.rotateSelection(-5 * (Math.PI / 180));
}

Link to comment
Share on other sites

  • 2 years later...

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.
×
×
  • Create New...