6 Replies Latest reply on Apr 6, 2013 12:44 PM by sinious

    Curved Path with actionscript

    Charine -FB buggoop Level 1

      Hi I am building my first game. I'm aming to keep all code in seperate actionscript files (one for each class and a main constructor .as) linked to my fla.

       

      So far I have added the backgound movieclip and one moving object (mc). i.e. 2 class files) It all looks great so far.

       

      In my game I have a projectile (first of many) falling out of a specific x;y point. I have a timer to change the x;y positions. This works well but it is going in a straight line.From parabola formulas I know y = x^2 or y = x*x, but these don't work.

       

      1) Please tell me what code to use to make a projectile's path curved or do I need a physics engine to handle this? Any ointers to tutorials will be much appreciated.

      2) I'm going to have many of these items fall out from the same x;y coordinates but i'd like the curve to vary. So I suppose I must add a random number to the formula - i. How do I do that? In normal life I would do y = x^2 + i.

      3) The "falling projectiles" are all going to match letters of the alphabet, so I suppose I will not have different instances of the same movieclip but rather different classes for each letter. Am I on the right path? How taxing will this be on my swf file size?

       

      Here is the very basic, but perfectly working code so far:

          import flash.display.MovieClip;
          public class A extends MovieClip
          {
              public function A()
              {
                  x = 300;
                  y = 30;
                  alpha = 0.1;

       

              }
              public function fadeIn():void
              {
                  alpha = alpha + 0.06;
              }

       

              public function moveWithCurve():void
              {
                  x = x + 3;
                  y = y + 4;
              }
          }
      }

       

      Message was edited by: buggerschool