ulfben icon

Rotate around center (or arbitrary points)

ulfben | PRO | 11/18/16 05:10:32 PM UTC | 0 ⭐ | 11305 👁️ | Never ⏰ | []
ActionScript 3 |

0 B

|

None

|

0 👍

/

0 👎

//0. translate the center of the DisplayObject to 0,0 (or an arbitrary offset)
//1. then rotate it 
//2. and then translate it back.
 
//using Matrix: 
public function centeredRotation(degrees:Number):void {
    if (this.rotation == degrees) { return; }
    var matrix:Matrix = this.transform.matrix;
    var rect:Rectangle = this.getBounds(this.parent);
    matrix.translate(-(rect.left + (rect.width*0.5)), -(rect.top + (rect.height*0.5)));
    matrix.rotate((degrees / 180) * Math.PI);
    matrix.translate(rect.left + (rect.width*0.5), rect.top + (rect.height*0.5));
    this.transform.matrix = matrix;
    this.rotation = Math.round(this.rotation);
}
 
//without Matrix
private function centeredRotation(degrees:Number):void{
    if (degrees == this.rotation){return;}
    var bounds:Rectangle = this.getBounds(this.parent);
    var center:Point = new Point(bounds.x + bounds.width*0.5, bounds.y + bounds.height*0.5);
    this.rotation = degrees;
    bounds = this.getBounds(this.parent);
    var newCenter:Point = new Point(bounds.x + bounds.width*0.5, bounds.y + bounds.height*0.5);
    this.x += center.x - newCenter.x;
    this.y += center.y - newCenter.y;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  • Rteuixl icon
    04/02/26 04:38:04 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎