2014-12-22 6 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}); 

                } 
    } 
}} 

그것은 파란색 원을 빨간색 원으로 이동시키는 코드입니다. https://api.monosnap.com/image/download?id=KhiUFE97lNbVkkSoVlxfsfyUeJM2v1는 당신이 볼 수있는 것처럼, 빨간색 원의 x 축이 500로 설정되어TweenLite AS3는 움직이는 물체를 가지고 있습니다.

, Y 축 (100) Tweenlite 대상 포인트로 설정이 빨간색으로 설정됩니다 https://api.monosnap.com/image/download?id=nLQQXmInSsSCqhRxjF2XaneWUpnVWm

마우스 이벤트 후 : 마우스 이벤트 전에

원의 x 축과 100입니다. 그러나 의도적 인 X 축의 동작과 같이 이상한 Y 축의 동작이 X 축에만 이동합니다. 0에서 100이 아니라 파란색 원의 현재 위치에서 +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 축의 위치에 나타나고 파란색 원이 빨간색으로 이동합니다. –

관련 문제