A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: rotating a box around one of its corners

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    15

    rotating a box around one of its corners

    Ok, I have a box with the registration point (little white circle) right in the middle. I would like this box to be able to rotate around any of its four corners (only around one at a time obviously, but able to rotate around any one if specified), as if the registration point was on that corner.

    I figure I would have to get the co-ordinates of that corner, then move and rotate the box by some value to keep the corner in the same position? If that's right, or not, then question is how?

    Hope you understand what I'm getting at here..

    Thanks

  2. #2
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159
    use the matrix

    of course you need to know the position of the corner... so find that with respect to the DisplayObject's coordinate space.

    Next it's a few steps:

    transform the point to the the coordinate space the matrix exists in
    subtract the point from the position of the matrix
    rotate by the amount of radians you want to
    add the point back onto the matrix

    from the fl.motion.MatrixTransformer class:

    code:

    /**
    * Rotates a matrix about a point defined inside the matrix's transformation space.
    * This can be used to rotate a movie clip around a transformation point inside itself.
    *
    * @param m A Matrix instance.
    *
    * @param x The x coordinate of the point.
    *
    * @param y The y coordinate of the point.
    *
    * @param angleDegrees The angle of rotation in degrees.
    * @playerversion Flash 9.0.28.0
    * @langversion 3.0
    * @keyword Matrix, Copy Motion as ActionScript
    * @see flash.geom.Matrix
    */
    public static function rotateAroundInternalPoint(m:Matrix, x:Number, y:Number, angleDegrees:Number):void
    {
    var point:Point = new Point(x, y);
    point = m.transformPoint(point);
    m.tx -= point.x;
    m.ty -= point.y;
    m.rotate(angleDegrees*(Math.PI/180));
    m.tx += point.x;
    m.ty += point.y;
    }

    I do not vow to know everything, and I can not guarantee what I say is correct. We are all learning, and I actually thank you the one with the questions for asking and stimulating my mind.

    www.lordofduct.com - check out my blog, or contact me through my website. I'm always available for freelance work in Flex3/Actionscript 3.

    how many times must I say it... the livedocs are your friend!
    http://livedocs.adobe.com/flash/9.0/...l-classes.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center