Posted By

burakkirkil on 07/29/12


Tagged


Versions (?)

Tween3D - 3D Deformation Resolver&Helper


 / Published in: ActionScript 3
 

Simple static 3D Deformation Resolver&Helper

  1. package tr.com.gotoandrock.utils
  2. {
  3. import com.greensock.TweenLite;
  4.  
  5. import flash.display.DisplayObject;
  6. import flash.geom.Matrix;
  7.  
  8. /**
  9. * Helps 3d tranformation applied target back to normal 2D Matrix and look&feel :)
  10. * Should only use tween ends with if z value equal 0;
  11. * Attention Please: onComplete and onCompleteParams overrides
  12. * @author Burak Kırkıl
  13. *
  14. */
  15. public class Tween3D
  16. {
  17. public static function to(target:DisplayObject, duration:Number, vars:Object):void
  18. {
  19. TweenLite.to(target, duration, scaleTargetAndGet2dVars(target, vars));
  20. }
  21.  
  22. public static function from(target:DisplayObject, duration:Number, vars:Object):void
  23. {
  24. TweenLite.from(target, duration, scaleTargetAndGet2dVars(target, vars));
  25. }
  26.  
  27. //////////////////////////////////////////////////////
  28. // PRIVATE FUNCS
  29. //////////////////////////////////////////////////////
  30. private static function scaleTargetAndGet2dVars(target:DisplayObject, vars:Object):Object
  31. {
  32. // create vars
  33. vars.onComplete = backTo2DTarget;
  34. vars.onCompleteParams = [target, target.transform.matrix];
  35. // scale target
  36. target.scaleX = target.width / (target.width + 1);
  37. target.scaleY = target.height / (target.height + 1);
  38. return vars;
  39. }
  40.  
  41. private static function backTo2DTarget(target:DisplayObject, matrix2d:Matrix):void
  42. {
  43. // normalize matrix
  44. target.transform.matrix = matrix2d;
  45. target.transform.matrix3D = null;
  46. }
  47. }
  48. }

Report this snippet  

You need to login to post a comment.