Skip to content

Instantly share code, notes, and snippets.

@diverted247
Created January 8, 2015 16:40
Show Gist options
  • Save diverted247/d04eb3bc375b9ab145c3 to your computer and use it in GitHub Desktop.
Save diverted247/d04eb3bc375b9ab145c3 to your computer and use it in GitHub Desktop.
rotateOnCenter using Matrix2D logic from 0.7.1
// Rotates a DisplayObject on center by angleInDegrees
private rotateOnCenter( component:createjs.DisplayObject , x:number , y:number , angleInDegrees:number ):void {
// Make a new Matrix
var m = new createjs.Matrix2D( 1 , 0 , 0 , 1 , 0 , 0 );
// Transform midpoint into matrix space
var point = new createjs.Point( 0 , 0 );
point = m.transformPoint( x , y , point );
// Translate matrix by point to center component on matrix
m.tx -= point.x;
m.ty -= point.y;
// (Counter)rotate component by input degrees
m.rotate( angleInDegrees * ( Math.PI/180.0 ) );
// Translate component back to position in matrix
m.tx += point.x;
m.ty += point.y;
// Apply component matrix to rotation matrix
m.prependMatrix( component.getMatrix(null) );
// Apply combined matrix to component
m.decompose( component );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment