사람님2015.03.16 18:59

코드


package {

import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.Event;


   public class Main extends MovieClip {

      private var p1: Point;
      private var p2: Point;
      private var progress: Number = 0;

      private var points: Array;
      private var index: int = 0;

      // 생성자
      public function Main() {
         addEventListener(Event.ADDED_TO_STAGE, Start);
      }

      // 초기화합니다.
      private function Start(e: Event): void {
         removeEventListener(Event.ADDED_TO_STAGE, Start);

         // 드로잉에 필요한 꼭지점들을 배열로 가지고 있습니다.
         points = new Array();
         points.push(new Point(stage.stageWidth / 2, 0));
         points.push(new Point(stage.stageWidth, 0));
         points.push(new Point(stage.stageWidth, stage.stageHeight / 2));
         points.push(new Point(stage.stageWidth, stage.stageHeight));
         points.push(new Point(stage.stageWidth / 2, stage.stageHeight));
         points.push(new Point(0, stage.stageHeight));
         points.push(new Point(0, stage.stageHeight / 2));
         points.push(new Point(0, 0));
         points.push(new Point(stage.stageWidth / 2, 0));

         // 0번째 점이 시작점입니다.

         // 다음 점을 구하는 함수를 만듭니다.

         // 다음 점을 구할 때마다 인덱스를 1씩 증가시킵니다.
         p1 = points[0];
         p2 = nextPoint();

         addEventListener(Event.ENTER_FRAME, Update);
      }

      // 시간이 업데이트될 때마다 호출됩니다.
      private function Update(e: Event): void {

         // 진행도를 0.01 늘립니다. 진행도는 매 꼭지점마다 0~1사이의 값이 됩니다.
         progress += 0.01;

         // 이전프레임에서 그린 그래픽을 제거합니다.
         graphics.clear();

         graphics.beginFill(0xff0000, 0.5);

         // 스테이지 중심점에서 그리기시작합니다.
         graphics.moveTo(stage.stageWidth / 2, stage.stageHeight / 2);

         // index까지 그려줍니다.
         for (var i: int = 0; i < index; i++) {
            graphics.lineTo(points[i].x, points[i].y);
         }

         // 진행도만큼 그려줍니다.
         graphics.lineTo(p1.x, p1.y);
         graphics.lineTo(p2.x * progress + p1.x * (1 - progress), p2.y * progress + p1.y * (1 - progress));

        // 진행도가 1 이상이 되면 0으로 바꾸어주고 드로잉할 다음 점을 구합니다.

        // 전체의 진행도는 (index+progress)/점 배열 길이로 구할 수 있습니다.
         if (progress >= 1) {
            progress = 0;
            p1 = p2;
            p2 = nextPoint();
            if (p2 == null) {
               removeEventListener(Event.ENTER_FRAME, Update);

              // 다음 점이 없으면 쿨 타임이 완료된 것입니다.
               // DO SOMETHING !
            }
         }
      }

      // 인덱스를 1 늘리고 다음 점을 구합니다.
      private function nextPoint(): Point {
         index++;

         if (index == points.length) {
            return null;
         }

         return points[index];
      }

   }

}

파일 첨부

여기에 파일을 끌어 놓거나 파일 첨부 버튼을 클릭하세요.

파일 크기 제한 : 0MB (허용 확장자 : *.*)

0개 첨부 됨 ( / )






[개인정보취급방침] | [이용약관] | [제휴문의] | [후원창구] | [인디사이드연혁]

Copyright © 1999 - 2016 INdiSide.com/(주)씨엘쓰리디 All Rights Reserved.
인디사이드 운영자 : 천무(이지선) | kernys(김원배) | 사신지(김병국)