Created
January 8, 2015 16:40
-
-
Save diverted247/d04eb3bc375b9ab145c3 to your computer and use it in GitHub Desktop.
rotateOnCenter using Matrix2D logic from 0.7.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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