0 Replies Latest reply on May 6, 2010 3:06 AM by LivingDeadBeat

    Tweening a distorted image

    LivingDeadBeat

      Hi

       

      I''m using the distortImage class to make an image appear 3d and i would like to tween it so it moves to the centre of the screen and is "flat". Here is an image of what i'm trying to do.

       

      tween.png

       

      Basically i need to tween all the points that i passed to the distort class and update it on the tween update.  I've extended the tweenEffect class and tweenInstance class to handle points, which i found out how to do in a tutorial.  I don't know what i should be passing the tween though.  Here is the class i got from the tutorial

       

       

      public class MoveImage extends TweenEffect{public class MoveImage extends TweenEffect{
                
           public var pointsTo:Array;
           
           public function MoveImage(target:Object=null){
                super(target);
                this.instanceClass = MoveImageInstance;               
           }
                
           override public function getAffectedProperties():Array{
                return['points'];               
           }
                
           override protected function initInstance(instance:IEffectInstance):void{
                super.initInstance(instance);
                MoveImageInstance(instance).pointsTo = pointsTo;          
           }
                
      }
      
       
      
      

       

      and the instance class is this

       

      public class MoveImageInstance extends TweenEffectInstance{
                
                public var pointsTo:Array;
                private var pointsFrom:Array;
                
                public function MoveImageInstance(target:Object){
                     super(target);
                     trace('1');
                }
                
                override public function play():void{
                     super.play();
                     pointsFrom = target.points;
                     
                     if(!(pointsTo is Array)){
                          pointsTo = target.points;
                     }
                     
                     var fromP:Array = new Array(pointsFrom.length * 2);
                     var toP:Array = new Array(pointsTo.length * 2);
                     var c:int = 0;
                     
                     for(var i:int = 0; i < fromP.length; i += 2){
                          fromP[i] = pointsFrom[c].x;
                          fromP[i+1] = pointsFrom[c].y;
                          toP[i] = pointsTo[c].x;
                          toP[i+1] = pointsTo[c].y;
                          c++;
                     }          
                     
                     var tween:Tween = createTween(this, fromP, toP, duration);               
                }
                
                override public function onTweenEnd(value:Object):void{
                     super.onTweenEnd(value);
                }
                
                override public function onTweenUpdate(value:Object):void{               
                     var p:Array = new Array(Math.floor(value.length / 2));
                     var c:int = 0;
                     for(var i:int = 0; i < value.length; i += 2){
                          p[c] = new Point(value[i], value[i+1]);
                          c++;               
                     }
                     target.points = p;
                }
                               
           }
      

       

      The distort class has a method which takes a shape, a bitmap and 4 points to create the distorted image. Like this.

       

      distortion.setTransform(shape.graphics, bitmap.bitmapData, topLeft, topRight, bottomRight, bottomLeft);
      

       

      So i want to tween the above.  Any help would be muchly appreciated

       

      Thanks

      Tom