2014-12-22 78 views
0
package { 
import com.greensock.*; 
import flash.display.*; 
import flash.events.*; 
import flash.geom.*; 

public class shieet extends Sprite 
{ 
    public function shieet() 
    { 
     var PosY:Number = Math.floor(Math.random()*(stage.stageHeight-30)); 
     var PosX:Number = 0; 
     var PosX2:Number = 500; 

     var CircleBlue:MovieClip = new MovieClip(); 
     CircleBlue.graphics.lineStyle(2, 0); 
     CircleBlue.graphics.beginFill(0x0000FF); 
     CircleBlue.graphics.drawCircle(PosX,PosY,30); 
     graphics.endFill(); 
     addChild(CircleBlue); 

     PosY = Math.floor(Math.random()*(stage.stageHeight-30)); 
     var CircleRed:MovieClip = new MovieClip(); 
     CircleRed.graphics.lineStyle(2, 0); 
     CircleRed.graphics.beginFill(0xFF0000); 
     CircleRed.graphics.drawCircle(PosX2,100,30); 
     graphics.endFill(); 
     addChild(CircleRed); 
     stage.addEventListener(MouseEvent.CLICK,move_circle); 

     function move_circle(event:MouseEvent):void { 

       TweenLite.to(CircleBlue,4, {x:PosX2, y:100}); 

                } 
    } 
}} 

這是我的代碼,用於將藍色圓圈移動到紅色圓圈。TweenLite AS3 isse與移動物體

鼠標事件之前:https://api.monosnap.com/image/download?id=nLQQXmInSsSCqhRxjF2XaneWUpnVWm

鼠標事件之後:https://api.monosnap.com/image/download?id=KhiUFE97lNbVkkSoVlxfsfyUeJM2v1

就像你所看到的,紅色的圓的x軸設定爲500,Y軸設定爲100 TweenLite的目標點設置爲紅色圓的X軸和100. 但它只能像X軸一樣移動,Y軸的行爲奇怪如地獄。看起來它從藍圈的當前位置移動到+100點,而不是從0移到100。 我甚至不知道該做什麼,嘗試了很多東西。

回答

0

問題是紅色和藍色圓圈的原點仍然在0,0。試試這個,而不是...

package { 
    import com.greensock.*; 
    import flash.display.*; 
    import flash.events.*; 
    import flash.geom.*; 

    public class shieet extends Sprite { 
     public function shieet() { 
      var PosY:Number = Math.floor(Math.random()*(stage.stageHeight-30)); 
      var PosX:Number = 0; 
      var PosX2:Number = 500; 

      var CircleBlue:MovieClip = new MovieClip(); 
      CircleBlue.graphics.lineStyle(2, 0); 
      CircleBlue.graphics.beginFill(0x0000FF); 
      CircleBlue.graphics.drawCircle(0,0,30); 
      graphics.endFill(); 
      addChild(CircleBlue); 
      // Now that the graphic is on the center of the MC, move the MC, not the drawing. 
      CircleBlue.x = PosX; 
      CircleBlue.y = Math.floor(Math.random()*(stage.stageHeight-30)); 

      PosY = Math.floor(Math.random()*(stage.stageHeight-30)); 
      var CircleRed:MovieClip = new MovieClip(); 
      CircleRed.graphics.lineStyle(2, 0); 
      CircleRed.graphics.beginFill(0xFF0000); 
      CircleRed.graphics.drawCircle(0,0,30); 
      graphics.endFill(); 
      addChild(CircleRed); 
      CircleRed.x = PosX2; 
      CircleRed.y = 100; 

      stage.addEventListener(MouseEvent.CLICK,move_circle); 

      function move_circle(event:MouseEvent):void { 
       TweenLite.to(CircleBlue,4, {x:PosX2, y:100}); 
      } 
     } 
    } 
} 
+0

感謝您的答案,不知道你需要特定的X和Y軸後添加圈。我稍微改變了我的代碼,所以藍色和紅色圓圈出現在隨機Y軸的位置,藍色圓圈出現在紅色的位置。 –