Menu

Bug in AnimationPackage3's CubicCurve?

Help
2007-01-05
2013-04-01
  • Bjørn Børresen

    Hi, I've discovered some strange functionality in the latest AnimationPackage for AS3. It seems that when you add CubicCurves in a Sequence and animate it the target Sprite is moved when the next curve in the sequence starts to animate.

    If you run this code you'll see the problem quite clearly:

    package {
        import flash.display.Sprite;
        import de.alex_uhlmann.animationpackage.*;
        import de.alex_uhlmann.animationpackage.animation.*;
        import de.alex_uhlmann.animationpackage.drawing.*;
        import de.alex_uhlmann.animationpackage.utility.*;
        import com.robertpenner.easing.*;

        public class ASTester extends Sprite
        {

            public var duration:Number = 20000;
            private var curve2:CubicCurve;
           
            public function ASTester()
            {
                var target:Sprite = new Sprite();       
                target.opaqueBackground = false;
                   
                var seq:Sequence = new Sequence();
                seq.setAnimateMode(Sequence.JOIN);
                seq.animationStyle(duration);

                var curve:CubicCurve = new CubicCurve(target, 0, 0, 20, 30, 30, 50, 60, 60);
                curve.lineStyle(2,0xff0000,1);
               
                curve2 = new CubicCurve(target, 60, 60, 100, 100, 150, 110, 180, 121);
                curve2.lineStyle(2,0x00ff00,1);
               
                var curve3:CubicCurve = new CubicCurve(target, 180, 121, 200, 200, 222, 222, 259, 180);
                curve3.lineStyle(2,0xff5500,.5);
                       
                seq.addChild(curve);
                seq.addChild(curve2);
                seq.addChild(curve3);
           
                curve.animate(0, 100);
                seq.animate(0, 100);
                           
                this.addChild(target);
              
            }
        }
    }

    Is it a bug, or am I missing something here? :-)

     
    • Bjørn Børresen

      err.. the "curve.animate(0,100)" line shouldn't be there, but removing it doesn't change anything.

       
    • Alex Uhlmann

      Alex Uhlmann - 2007-01-07

      Hi Bjorn (sorry, don't have these nice (swedish?) letters on my keyboard,

      in your example above you're using the same Sprite for different Curve instances. This is why this is happending. I think you want to have a seperate display object for each curve or? Then it would look like this:

                  var target:Sprite = new Sprite(); 
                  target.opaqueBackground = false;
                  var target2:Sprite = new Sprite(); 
                  target2.opaqueBackground = false;
                  var target3:Sprite = new Sprite(); 
                  target3.opaqueBackground = false;                        
                  
                  var seq:Sequence = new Sequence();
                  seq.setAnimateMode(Sequence.JOIN);
                  seq.animationStyle(duration);
                  
                  var curve:CubicCurve = new CubicCurve(target, 0, 0, 20, 30, 30, 50, 60, 60);
                  curve.lineStyle(2,0xff0000,1);
                  
                  curve2 = new CubicCurve(target2, 60, 60, 100, 100, 150, 110, 180, 121);
                  curve2.lineStyle(2,0x00ff00,1);
                  
                  var curve3:CubicCurve = new CubicCurve(target3, 180, 121, 200, 200, 222, 222, 259, 180);
                  curve3.lineStyle(2,0xff5500,.5);
                  
                  seq.addChild(curve);
                  seq.addChild(curve2);
                  seq.addChild(curve3);
                  
                  //curve.animate(0, 100);
                  seq.animate(0, 100);
                  
                  this.addChild(target);   
                  this.addChild(target2);
                  this.addChild(target3);

      Best,
      Alex

       
    • Bjørn Børresen

      Hi Alex, and thanks for answering. The ø is Norwegian actually ;-)

      >in your example above you're using the same Sprite for different Curve instances.
      >This is why this is happending. I think you want to have a seperate display object for each curve or?

      I'm not sure .. I'm fairly new to AS. But I did test it with a new Sprite for each curve just after I wrote the message above, and I saw that it worked - however, it does seem like a bit of a hack to me? I mean, wouldn't it be preferable to have one Sprite with all the curves? You see, we're creating an application with hundreds of curves so I'm thinking maybe it would be a waste of resources to create a new Sprite for each curve?

      Besides, the behaviour with the Sprite's start x/y position being moved for each added seems kind of buggy to me?

      hehe, then again, as I said, I'm kind of a newbie when it comes to AS so I might be mistaken.

      - Bjørn

       
    • Alex Uhlmann

      Alex Uhlmann - 2007-01-07

      Hi Bjorn,

      You could create one display object that draws the complete curve. Checkout the drawBy (maybe drawTo) methods of each IOutline class. These methods can draw into the same graphics property without clearing it. Checkout Drawer to see how they fit together. Basically, this way you draw continously into one display object. However, this also means that you can only manipulate i.e. clear the display objects as a whole. It's impossible to just remove one part of a display object. So, having way no. 1 is more flexible, no. 2 is faster.

      However, maybe in your app, drawing hundreds of Curve instances will work fine. Have you already experienced that it wouldn't work? If you find the first way to be faster for you, I'd be carefull to do any premature optimizations. XP rule: Don't invest in tomorrow. ;)

      Best,
      Alex

       
    • Alex Uhlmann

      Alex Uhlmann - 2007-01-07

      I should have added that I recommend checking out the documentation from AP 1 or AP 2 for now. Most API's are still the same and i.e. for Drawer, there's a lot more documentation on this than via the AS3 asdoc docs, which is just API docs.

      So, check out:
      http://www.alex-uhlmann.de/flash/animationpackage/ap2/index.htm
      >Drawer

      Best,
      Alex

       
    • Bjørn Børresen

      I think it will work fine with a new Sprite for each curve. I did a test today and I didn't experience any slowness. Agree with you on premature optimization btw ;)

      Thanks alot for taking the time to answer my post, Alex! :)

      Best regards,
      Bjørn

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.