9 Replies Latest reply on Jan 19, 2009 12:41 PM by shintashi

    how to move a particle system with arrow keys?

    shintashi Level 1
      I have a little "ice fountain" particle effect and I want to be able to move it like an object. How do I use actionscript to effect a group particle system? (or have collision detection features for that matter)


      Code:
      --------------------------------------------------------------------------
      this.createEmptyMovieClip("holder2_mc", this.getNextHighestDepth());
      for(i=0;i<50;i++) {
      var k:MovieClip = holder2_mc.attachMovie("ice","ice"+i ,holder2_mc.getNextHighestDepth());
      k._y = 350;
      k._xscale = Math.random()* 55 + 35;
      k._yscale = Math.random()* 55 + 35;
      k._x = Stage.width/2 -150;
      k._rotation += Math.random()* 90 -45;
      k.gotoAndPlay(Math.ceil(Math.random()*16));

      }
        • 1. how to move a particle system with arrow keys?
          clbeech Level 3
          hey shintashi - you could use an enterframe loop or interval to move the holder clip, or you could constantly loop through the instances and adjust their positions given a key input check by adding to the position value.

          the latter may be better for you if you are wanting to also check for a hitTest against the character instance.
          • 2. Re: how to move a particle system with arrow keys?
            shintashi Level 1
            Thank you for the advice on movement!


            One thing that seems to be perturbing, however, is the ._rotation issue. The particle system can be rotated, but it rotates about a center other than the apparent holder. The radius appears to increase proportionate to the rotation angle, so 1-10 degrees is still visible but 90 degrees disappears completely off the screen in fractions of a second.
            • 3. Re: how to move a particle system with arrow keys?
              kglad Adobe Community Professional & MVP
              k will rotate about its registration point.
              • 4. Re: how to move a particle system with arrow keys?
                shintashi Level 1
                I did some checking (using full screen)

                and the registration point appears to be precisely 0,0 of the stage. Is there a way to change this so it's center is where-ever it currently is? (such as a base coordinate later modified by arrow key/ y/x +/-)
                • 5. Re: how to move a particle system with arrow keys?
                  clbeech Level 3
                  the holder MC's registration point should be at 0,0 but the coordinates of the clip(s) k should not be according to the code above, their coordinates are relative to the container. are you certain that you are rotating the correct clip? 'outside' of the loop the reference path to the instances should be:

                  holder2_mc.ice0._rotation //instances: ice[0 through 49]
                  • 6. Re: how to move a particle system with arrow keys?
                    kglad Adobe Community Professional & MVP
                    k is not at 0,0. its at (Stage.width/2 -150,350) and that's what it will rotate around
                    • 7. Re: how to move a particle system with arrow keys?
                      shintashi Level 1
                      this is the code, and its clearly rotating about 0,0.


                      onEnterFrame = function(){
                      if(Key.isDown(Key.UP)){
                      holder2_mc._y -= 5;
                      }
                      if(Key.isDown(Key.DOWN)){
                      holder2_mc._y += 5;
                      }
                      if(Key.isDown(Key.LEFT)){
                      holder2_mc._x -= 5;
                      }
                      if(Key.isDown(Key.RIGHT)){
                      holder2_mc._x += 5;
                      }

                      if(Key.isDown(Key.SPACE)){
                      holder2_mc._rotation += 15;
                      }


                      }

                      this.createEmptyMovieClip("holder2_mc", this.getNextHighestDepth());
                      for(i=0;i<150;i++) {
                      var k:MovieClip = holder2_mc.attachMovie("ice","ice"+i ,holder2_mc.getNextHighestDepth());
                      k._y = 350;
                      k._xscale = Math.random()* 55 + 35;
                      k._yscale = Math.random()* 75 + 25;
                      k._x = Stage.width/2 -150;
                      k._rotation += Math.random()* 90 -45;
                      k.gotoAndPlay(Math.ceil(Math.random()*16));
                      //k._y -= Math.random()* 100 +25;
                      //k._x += Math.random()* 100 -50;



                      }

                      • 8. Re: how to move a particle system with arrow keys?
                        kglad Adobe Community Professional & MVP
                        k, doesn't rotate around 0,0 and that was the only rotation you showed in the only relevant post.
                        • 9. Re: how to move a particle system with arrow keys?
                          shintashi Level 1
                          fixed:
                          holder2_mc coordinates had to be loaded outside onEnterframe and outside the "for" but inside an onLoad, and the initial k coordinates had to be shut down.

                          ------------- Code --------------------
                          onLoad = function(){
                          holder2_mc._y = 350;
                          holder2_mc._x = Stage.width/2;
                          }
                          onEnterFrame = function(){



                          if(Key.isDown(Key.UP)){
                          holder2_mc._y -= 5;
                          }
                          if(Key.isDown(Key.DOWN)){
                          holder2_mc._y += 5;
                          }
                          if(Key.isDown(Key.LEFT)){
                          holder2_mc._x -= 5;
                          }
                          if(Key.isDown(Key.RIGHT)){
                          holder2_mc._x += 5;
                          }

                          if(Key.isDown(Key.SPACE)){
                          //trace(holder2_mc._y);

                          holder2_mc._rotation += 15;
                          }


                          }

                          this.createEmptyMovieClip("holder2_mc", this.getNextHighestDepth());
                          for(i=0;i<150;i++) {
                          var k:MovieClip = holder2_mc.attachMovie("ice","ice"+i ,holder2_mc.getNextHighestDepth());
                          //k._y = 350;
                          k._xscale = Math.random()* 55 + 35;
                          k._yscale = Math.random()* 75 + 25;
                          //k._x = Stage.width/2 -150;
                          k._rotation += Math.random()* 90 -45;
                          k.gotoAndPlay(Math.ceil(Math.random()*16));
                          //k._y -= Math.random()* 100 +25;
                          //k._x += Math.random()* 100 -50;
                          }