Created
July 21, 2013 06:38
-
-
Save RKAN/6047728 to your computer and use it in GitHub Desktop.
Tween3D - 3D Deformation Resolver&Helper
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
package tr.com.gotoandrock.utils | |
{ | |
import com.greensock.TweenLite; | |
import flash.display.DisplayObject; | |
import flash.geom.Matrix; | |
/** | |
* Helps 3d tranformation applied target back to normal 2D Matrix and look&feel :) | |
* Should only use tween ends with if z value equal 0; | |
* Attention Please: onComplete and onCompleteParams overrides | |
* @author Burak Kırkıl | |
* | |
*/ | |
public class Tween3D | |
{ | |
public static function to(target:DisplayObject, duration:Number, vars:Object):void | |
{ | |
TweenLite.to(target, duration, scaleTargetAndGet2dVars(target, vars)); | |
} | |
public static function from(target:DisplayObject, duration:Number, vars:Object):void | |
{ | |
TweenLite.from(target, duration, scaleTargetAndGet2dVars(target, vars)); | |
} | |
////////////////////////////////////////////////////// | |
// PRIVATE FUNCS | |
////////////////////////////////////////////////////// | |
private static function scaleTargetAndGet2dVars(target:DisplayObject, vars:Object):Object | |
{ | |
// create vars | |
vars.onComplete = backTo2DTarget; | |
vars.onCompleteParams = [target, target.transform.matrix]; | |
// scale target | |
target.scaleX = target.width / (target.width + 1); | |
target.scaleY = target.height / (target.height + 1); | |
return vars; | |
} | |
private static function backTo2DTarget(target:DisplayObject, matrix2d:Matrix):void | |
{ | |
// normalize matrix | |
target.transform.matrix = matrix2d; | |
target.transform.matrix3D = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment