5 Replies Latest reply on Oct 5, 2010 11:14 AM by kglad

    Rotate a Object Around Center Axis

    VanillaBeast

      Hey peoples, new to flash here.  I'm using CS3 with ActionScript 3.0.  What I want is simple, and I've done some searching but nothing that can get me the right results.  I'm going to post a link that does exactly what I want:

       

      http://www.newgrounds.com/dump/item/d25a3dd46f2ff49f2ec892c425cbbd1e

       

      This rotates the circular object around a center point in a way that you can distort the object yet is still remains turning in a circular motion.  A simple motion tween rotating the image will only work if the object is perfectly round, so distorting the object to make it more straight or curved won't work with a simple tween.  I want to do exactly what is happening here (with my own object), is there some AS3 behind the scenes here making this turn on a center point??  Thanks for the help

        • 1. Re: Rotate a Object Around Center Axis
          kglad Adobe Community Professional & MVP

          whenever you change your objects width or height, reassign it to its parent using an offset and rotate the parent.   ie, you can pass your object to recenterF whenever there's a change.

           

           

          function recenterF(c:Sprite):void{

          c.x=-c.width/2;

          c.y=-c.height/2;

          }

           

           

          // p.s.  don't forget, you'll be rotating (and in all other ways dealing with) the parent.

          • 2. Re: Rotate a Object Around Center Axis
            VanillaBeast Level 1

            This answer may be solve my issue, but I do not understand it.

             

            My current way of rotating this is to use a motion tween turning it ccw by rotating it, motion tween, rotating it, motion tween.  I'm thinking that way isn't best.  Also, I'm only dealing with one object here, so I'm not sure I follow the whole parent child relationship.  I drop one object onto the stage, rotate it with a mask layer overtop only showing a small portion.  Should I be using multiple objects here?  Sorry, I'm not stupid, just very new to flash and its functionality.

            • 3. Re: Rotate a Object Around Center Axis
              kglad Adobe Community Professional & MVP

              this can be done using timeline tweening but it's going to be more difficult.  it will be easier to use actionscript to rotate your object.

              • 4. Re: Rotate a Object Around Center Axis
                VanillaBeast Level 1

                Yes, but I still don't know what you mean by the parent child relationship.  Lets say I use a simple rotate line like:

                 

                objectname.rotation = 360;

                 

                That should spin it, but how do I spin it correctly if the object is skewed like in the bottom right picture of my example?

                • 5. Re: Rotate a Object Around Center Axis
                  kglad Adobe Community Professional & MVP

                  you would use:

                   

                  var p:Sprite=new Sprite();

                  objectname.parent.addChild(p);

                  p.x=objectname.x+objectname.width/2;

                  p.y=objectname.y+objectname.height/2;

                  p.addChild(objectname);

                  objectname.x=-objectname/width/2;

                  objectname.y=-objectname/height/2;

                   

                  p.rotation = 360;  // this won't show anything useful, but using a rotation strictly between 0 and 360 will.