2011-05-24 27 views
1

コンテナ/親ムービークリップを拡大して、子の1つが参照するポイントを効果的に拡大しようとしています。私は、ステージの中央でその点を取得するためにglobalToLocalを使用する方法を考え出しましたが、問題は左上にコンテナクリップの登録ポイントがあり(そして保持する必要があります)、コンテナクリップをスケールするときですポイントは画面の中央には残りません。flash as3クリップ内の特定の点を拡大(拡大)する

//改訂::ここに私のコードです私はこれを行うと、ズームポイントはどこかの周りの「メイベルグリアの玩具ショップ」で終わる

var stageCenter = new Point(int(stage.stageWidth/2),int(stage.stageHeight)/2); 
    var parPointLocal = parRef.globalToLocal(stageCenter); 
    TweenMax.to(treeClip,.5,{x:parPointLocal.x,y:parPointLocal.y,onComplete:doZoom}); 

    function doZoom():void { 
     var zoomPoint = zoomToMember(treeClip,stageCenter,2); 

     function zoomToMember(target:MovieClip, center:Point, scale:Number):Point { 
      var m:Matrix = new Matrix(); 
      m.translate(-center.x, -center.y);//move the center into (0,0) 
      m.scale(scale, scale);//scale relatively to (0,0) (which is where our center is now) 
      m.translate(center.x, center.y);//move the center back to its original position 
      return m.transformPoint(new Point());//transform (0,0) using the whole transformation matrix to calculate the destination of the upper left corner 
     } 

     TweenMax.to (treeClip,.5,{x:zoomPoint.x,y:zoomPoint.y,scaleX:2,scaleY:2}) 

    } 

- 私は前の段階の中心点だったと想像"Jon Anderson"がステージの中央にくるようにtreeClipがトゥイーンされました。

screenshot

答えて

3

あなたはスケーリング後、左上隅の宛先位置を計算し、それにxとyプロパティをトゥイーンする必要があります。

最も簡単な方法は、行列を使用することです:

function scale(target:MovieClip, center:Point, scale:Number):Point { 
    var m:Matrix = new Matrix(); 
    m.translate(-center.x, -center.y);//move the center into (0,0) 
    m.scale(scale, scale);//scale relatively to (0,0) (which is where our center is now) 
    m.translate(center.x, center.y);//move the center back to its original position 
    return m.transformPoint(new Point());//transform (0,0) using the whole transformation matrix to calculate the destination of the upper left corner 
} 
+0

おかげ - I種の(すみません)それを得るが、私はそれを実装する場合、それは全く正しい場所にズームされていないようです。上記の私の説明を編集して、改訂されたコードを表示しました。あなたが提供できるどんな助けも素晴らしいでしょう。 – mheavers

+0

ああ、なぜmovieclip(ターゲット)が利用されていない場合は、関数のパラメータとしてムービークリップを含めましたか?それはすべきでしょうか? – mheavers

+0

ええ、ターゲットは実際には使用されていません:)。しかし、中心点が実際にグローバル座標空間で表現されている場合は、 'center = target.globalToLocal(center);'を実行する必要があります。 – back2dos