成都網(wǎng)頁設(shè)計AS3鼠標跟隨特效

2016-08-08    分類: 網(wǎng)站建設(shè)

package
{
import flash.display.Sprite;
import flash.events.Event;

public class FollowMouse extends Sprite
{
private var arrow:Arrow;
private var speed:Number = 5;

public function FollowMouse()
{
init();
}

private function init():void
{
arrow = new Arrow();
addChild(arrow);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
//先要計算出箭頭與鼠標的 x 距離和 y 距離,并使用 Math.atan2 計算出它們的夾角。然后使用這個角度使箭頭旋轉(zhuǎn),再使用 Math.cos 和 Math.sin 與速度相乘計算出 x,y 速度向量,最后將它們加到箭頭的坐標上。
var dx:Number = mouseX - arrow.x;
var dy:Number = mouseY - arrow.y;
var angle:Number = Math.atan2(dy, dx);
arrow.rotation = angle * 180 / Math.PI;
var vx:Number = Math.cos(angle) * speed;
var vy:Number = Math.sin(angle) * speed;
arrow.x += vx;
arrow.y += vy;
}
}

}

本文標題:成都網(wǎng)頁設(shè)計AS3鼠標跟隨特效
本文鏈接:http://www.muchs.cn/news3/40003.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序全網(wǎng)營銷推廣、網(wǎng)站策劃、服務(wù)器托管、靜態(tài)網(wǎng)站外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護公司