Star Trail Effect Follow Mouse

* Xem kết quả ở đây!!

Hướng dẫn thực hiện

Bước 1:

_ Tạo 1 file flash document kích thước 300×300 lưu với tên “StarTrailEffec.fla”. Màu nền là Đen (0×000000)

_ Chọn công cụ PolyStar Tool . Tiếp tục nhấn Properties rồi nhấn nút Option hiện ra cái bảng Tool Option chọn Start ở mục Style, chọn 0.10 ở mục Star point size.

_ Xong vẽ 1 ngôi sao trên Stage

flash-star-tool-settings

_ Convert nó thành MovieClip đặt tên là “MyStar”. Tiếp tục chọn cái movie vừa tạo đặt tên cho nó là “mainStar_mc”.
Vào library phải chuột vào movie MyStar chọn linkage cho nó đặt tên linkage chỗ Class là : “MyStar”

flash-movie-clip1-300x236

_ Trở lại Stage chính tạo mới 1 Layer chọn layer đó gắn đoạn code này vào :

CODE:

import com.StarEffect.StarTrail;
new StarTrail(this);

_ Lưu flash document lại và bắt đầu bước kế tiếp

Bước 2: Tạo 1 class “StarTrail.as” trong thư mục “com/StarEffect”

CODE:

package com.StarEffect {
import flash.display.MovieClip;
import flash.events.Event;

import gs.*;

import flash.utils.Timer;
import flash.events.TimerEvent;

import proxy.Proxy;

import flash.ui.Mouse;

/**
* @author yoko
*/
public class StarTrail {
private var ROOT : MovieClip;
private var MAIN_STAR : MovieClip;
private var NEW_STAR : MovieClip;
private var COLOR : uint = 0xFFFF00;
private var TRAIL_TIME : Timer,COLOR_TIME : Timer;

public function StarTrail(mainTimeLine : MovieClip) {
ROOT = mainTimeLine;
Mouse.hide();
ROOT.stage.frameRate = 24;
MAIN_STAR = ROOT.mainStar_mc;
//—————-
ROOT.addEventListener(Event.ENTER_FRAME, Proxy.create(moveStar));
//—————-
COLOR_TIME = new Timer(500, 0);
COLOR_TIME.addEventListener(TimerEvent.TIMER, Proxy.create(changeColor));
COLOR_TIME.start();
//—————-
TRAIL_TIME = new Timer(10, 0);
TRAIL_TIME.addEventListener(TimerEvent.TIMER, Proxy.create(createStar));
TRAIL_TIME.start();
}

private function moveStar(evt : Event) : void {
MAIN_STAR.x = ROOT.mouseX;
MAIN_STAR.y = ROOT.mouseY;
}

private function changeColor(evt : Event) : void {
COLOR = Math.random() * 0xFFFFFF;
TweenMax.to(MAIN_STAR, 0.2, {tint:COLOR});
}

private function createStar(evt : Event) : void {
NEW_STAR = new MyStar() as MovieClip;

NEW_STAR.x = MAIN_STAR.x;
NEW_STAR.y = MAIN_STAR.y;

var targetX : Number = NEW_STAR.x + Math.random() * 64 – 32;
var targetY : Number = NEW_STAR.y + Math.random() * 64 – 32;
var targetRotation : Number = Math.random() * 360 – 180;

ROOT.addChild(NEW_STAR);

TweenMax.to(NEW_STAR, 3, {alpha: 0, scaleX: 4, scaleY: 4/*, tint:COLOR*/});
TweenMax.to(NEW_STAR, 3, {rotation: targetRotation, x: targetX, y: targetY});
TweenMax.to(NEW_STAR, 3, {blurFilter:{blurX:3, blurY:3}, onComplete: Proxy.create(removeStar, NEW_STAR)});
}

private function removeStar(targetStar : MovieClip) : void {
ROOT.removeChild(targetStar);
}
}
// end
}

Bước 3: Ctrl+Enter để xem kết quả

Follow

Get every new post delivered to your Inbox.