Posted By

onemanstudio on 05/18/11


Tagged

path distance track travel bezier trails trail traveled


Versions (?)

AS3 Trails


 / Published in: ActionScript 3
 

URL: http://onemanstudio.eu/labs/rabbitTrails

AS3 Trails, just call checkDistance() during Your Tween

  1. package eu.onemanstudio
  2. {
  3. import flash.display.MovieClip;
  4. import flash.display.StageAlign;
  5. import flash.events.Event;
  6. import com.greensock.*;
  7. import com.greensock.easing.*;
  8. import eu.onemanstudio.Arrow;
  9.  
  10.  
  11. /**
  12. * ...
  13. */
  14. public class Main extends MovieClip
  15. {
  16. private var countX:Number = 0;
  17. private var lastX:Number = 0;
  18. private var currentX:Number = 0;
  19. private var differenceX:Number = 0;
  20. private var countY:Number = 0;
  21. private var lastY:Number = 0;
  22. private var currentY:Number = 0;
  23. private var differenceY:Number = 0;
  24.  
  25. private var howMany:int = 20; // Trail every 20 pixels traveled
  26.  
  27. private var eMCe:Arrow; //Trail MovieClip
  28. private var mc:Arrow; //Traveler
  29.  
  30. public function Main():void
  31. {
  32. if (stage) init();
  33. else addEventListener(Event.ADDED_TO_STAGE, init);
  34. }
  35.  
  36. private function init(e:Event = null):void
  37. {
  38. removeEventListener(Event.ADDED_TO_STAGE, init);
  39. // entry point
  40. stage.align = StageAlign.TOP_LEFT;
  41.  
  42. mc = new Arrow();
  43. addChild(mc);
  44. mc.x = 600;
  45. mc.y = 30;
  46.  
  47. TweenMax.to(mc, 15, {bezierThrough:[{x:60, y:183}, {x:400, y:440}, {x:320, y:570}, {x:520, y:70}], delay:2, orientToBezier:true, onUpdate:checkDistance});
  48. }
  49.  
  50.  
  51.  
  52.  
  53. private function checkDistance():void
  54. {
  55. currentX = mc.x;
  56. if(lastX && lastX != 0)
  57. {
  58. differenceX = lastX - currentX;
  59. if (differenceX <= 0) differenceX = differenceX * -1;
  60. }
  61. lastX = currentX;
  62. if (differenceX != 0) countX += Number(differenceX);
  63.  
  64. if (countX >= howMany) trail();
  65.  
  66. currentY = mc.y;
  67. if(lastY && lastY != 0)
  68. {
  69. differenceY = lastY - currentY;
  70. if(differenceY <=0) differenceY = differenceY * -1;
  71. }
  72. lastY = currentY;
  73. if (differenceY != 0) countY += Number(differenceY);
  74.  
  75. if (countY >= howMany) trail();
  76. }
  77.  
  78. private function trail():void
  79. {
  80. eMCe = new Arrow();
  81. addChild(eMCe);
  82. eMCe.x = mc.x;
  83. eMCe.y = mc.y;
  84. eMCe.scaleX = eMCe.scaleY = 0.2;
  85. eMCe.rotation = mc.rotation;
  86. countY = 0;
  87. countX = 0;
  88.  
  89. }
  90.  
  91.  
  92.  
  93. }
  94.  
  95. }

Report this snippet  

You need to login to post a comment.