用户ID :  密码 : 

登 录

注 册

时代财富科技公司 FortuneAge Technology Co., Ltd. 校园博客客服网站(新)

我的资料

moo

博客信息

积分:62
等级:1级 lv 1
日志总数:18
发表评论总数:3 (查看)
获得评论总数:1
发表留言总数:0
浏览总数:4550

最新公告

又开始写博啦...

我的日历

最新评论

RE:响应鼠标的动作实例
AS://捕捉鼠标划过的速度和划过的位置function ...

RSS

首页 -> 技術相关->响应鼠标的动作实例
响应鼠标的动作实例

 
 

制作思路

 

先说明:这个实例曾看过的一外国网站的一则效果。

先制作好鼠标划过不同部位所响应的动作特效,再用几个Movie Clip来捕捉鼠标划过的位置跟速度,然后播放不同的动作特效,这就是我们所看到的效果。

 

实现过程

  下面我们来看看粗略的实现过程。

 

  1、按“Ctrl + N”,新建一个Flash文件,按“Ctrl + F8”,新建一个Movie Clip,命名为“All Motion”

 

  2、进入此Movie Clip,用鼠标右键点击图层的名称,依次插入“label”“Action”“sound”“idle”四个图层,在“label”层的帧的属性面板上设置帧的label“c_idle”,同理,设置此帧的label依次为“ML_w” “ML_s”“MR_w”“MR_s”“TL_m”“TL_w”“TL_s”“TR_m”“TR_w”“TR_s”“B_m”“BL_w”“BL_s”“BR_w”“BR_s”

 

  3、在“Action”层的距“label”层每一标签前一帧点击鼠标右键,插入一个关键帧,在此帧的Action Script面板上面添加分别添加语句:gotoAndPlay(1);

    

4、接下来就是对小人动作的细化了,如果想要更好的效果,可以在适当的地方插入声音效果,这里不详细讲。见下图:
 

1

 

5、按“Ctrl + F8”新建一个Movie Clip,用绘图工具在这个Clip用画一个半圆。

 

6、回到影片的主场景中,在用鼠标右键点击图层名,插入4个图层,分别命名为“Action”“Hit_Area”“Motion_All”

 

  7、在“Motion_All”层的第1帧,将第14步所制作的Movie Clip从图库拖到场景中,在属性面板上设置实例名为“Motion_All”

 

  8、在“Hit_Area”层的第1帧,将第5步所制作的Movie Clip从图库拖六次到场景中,拼成一个图形如图2所示,并分别在属性面板上设置实例名为“Area_Head_Left”“Area_Arm_Left”“Area_Leg_Left”“Area_Head_Right”“Area_Arm_Right”“Area_Leg_Right”
 

2


  9、在“Action”层的第1帧的Action Script面板上面添加语句下所示。
 

3

  

小结

 

  呵呵。看到了吧,当鼠标在场景中的不同地方划过,场景中的小人都会有不同的反应。尤其有趣的是,当鼠标划过的速度不同的时候,反应的强弱也是不同的。这就跟游戏中的实现很相似了。这则实例是对Movie Clip的应用。

网友评论

AS:

//捕捉鼠标划过的速度和划过的位置

function CalVelocity()

{

    cursor_old_x = cursor_new_x;

    cursor_old_y = cursor_new_y;

    cursor_new_x = this._xmouse;

    cursor_new_y = this._ymouse;

    cursor_velocity = int(Math.sqrt(Math.pow(cursor_new_x - cursor_old_x, 2) + Math.pow(cursor_new_y - cursor_old_y, 2)));

} // End of the function

 

//判断鼠标划过地速度,分别为强、中、弱

function CalPoints()

{

    if (cursor_velocity > VEL_HIT_LIMIT)

    {

        divide_num = DIVIDE_NUM_STRIKE;

    }

    else if (cursor_velocity > VEL_SAL_LIMIT)

    {

        divide_num = DIVIDE_NUM_HIT;

    }

    else

    {

        divide_num = DIVIDE_NUM_SAL;

    } // end else if

    xdivide = (cursor_new_x - cursor_old_x) / divide_num;

    ydivide = (cursor_new_y - cursor_old_y) / divide_num;

    for (i = 0; i < divide_num; i++)

    {

        xpoint_array[i] = cursor_old_x + xdivide * (i + 1);

        ypoint_array[i] = cursor_old_y + ydivide * (i + 1);

    } // end of for

} // End of the function

 

//播放鼠标动作所触发的相应场景

function StartMotion()

{

    _root.Motion_all.gotoAndPlay(togo);

} // End of the function

 

//判断鼠标划过的位置,分别对应场景中的对象的头、手、脚

function HitCheck()

{

    for (i = 0; i < divide_num; i++)

    {

        if (Area_Head_Left.hitTest(xpoint_array[i], ypoint_array[i], true))

        {

            if (!Area_Head_Left.hitTest(cursor_old_x, cursor_old_y, true))

            {

                if (xpoint_array[i] > cursor_old_x)

                {

                    HitArea = "Area_Head_Left";

                    break;

                } // end if

            } // end if

            continue;

        } // end if

        if (Area_Head_Right.hitTest(xpoint_array[i], ypoint_array[i], true))

        {

            if (!Area_Head_Right.hitTest(cursor_old_x, cursor_old_y, true))

            {

                if (xpoint_array[i] < cursor_old_x)

                {

                    HitArea = "Area_Head_Right";

                    break;

                } // end if

            } // end if

            continue;

        } // end if

        if (Area_Arm_Left.hitTest(xpoint_array[i], ypoint_array[i], true))

        {

            if (!Area_Arm_Left.hitTest(cursor_old_x, cursor_old_y, true))

            {

                if (xpoint_array[i] > cursor_old_x)

                {

                    HitArea = "Area_Arm_Left";

                    break;

                } // end if

            } // end if

            continue;

        } // end if

        if (Area_Arm_Right.hitTest(xpoint_array[i], ypoint_array[i], true))

        {

            if (!Area_Arm_Right.hitTest(cursor_old_x, cursor_old_y, true))

            {

                if (xpoint_array[i] < cursor_old_x)

                {

                    HitArea = "Area_Arm_Right";

                    break;

                } // end if

            } // end if

            continue;

        } // end if

        if (Area_Leg_Left.hitTest(xpoint_array[i], ypoint_array[i], true))

        {

            if (!Area_Leg_Left.hitTest(cursor_old_x, cursor_old_y, true))

            {

                if (xpoint_array[i] > cursor_old_x)

                {

                    HitArea = "Area_Leg_Left";

                    break;

                } // end if

            } // end if

            continue;

        } // end if

        if (Area_Leg_Right.hitTest(xpoint_array[i], ypoint_array[i], true))

        {

            if (!Area_Leg_Right.hitTest(cursor_old_x, cursor_old_y, true))

            {

                if (xpoint_array[i] < cursor_old_x)

                {

                    HitArea = "Area_Leg_Right";

                    break;

                } // end if

            } // end if

        } // end if

    } // end of for

} // End of the function

 

if (_root.d_display)

{

    _level100.on_off.gotoAndStop("on");

}

else

{

    _level100.on_off.gotoAndStop("off");

} // end else if

 

stop ();

//隐藏用来捕捉鼠标动作的对象。

Area_Head_Left._visible = false;

Area_Head_Right._visible = false;

Area_Arm_Left._visible = false;

Area_Arm_Right._visible = false;

Area_Leg_Left._visible = false;

Area_Leg_Right._visible = false;

 

//初始化鼠标的参数。

cursor_old_x = 0;

cursor_old_y = 0;

cursor_new_x = 0;

cursor_new_y = 0;

cursor_velocity = 0;

HitArea = "";

divide_num = 1;

xpoint_array = new Array();

ypoint_array = new Array();

init = false;

 

//定义一些变量,分别用来判断鼠标是否以比较慢、中等、比较快的速度划过对象。

VEL_SAL_LIMIT = 70;

VEL_HIT_LIMIT = 180;

DIVIDE_NUM_STRIKE = 30;

DIVIDE_NUM_HIT = 24;

DIVIDE_NUM_SAL = 12;

 

//整个场景的启动函数,不断的循环,不断地对鼠标动作产生响应

onEnterFrame = function ()

{

    CalVelocity();

    CalPoints();

    HitCheck();

    if (!init)

    {

        HitArea = "";

        init = true;

    } // end if

    switch (HitArea)

    {

        case "Area_Head_Left":

        {

            if (divide_num == DIVIDE_NUM_SAL)

            {

                togo = "TL_w";

            }

            else if (divide_num == DIVIDE_NUM_HIT)

            {

                togo = "TL_m";

            }

            else if (divide_num == DIVIDE_NUM_STRIKE)

            {

                togo = "TL_s";

            } // end else if

            StartMotion();

            HitArea = "";

            break;

        }

        case "Area_Head_Right":

        {

            if (divide_num == DIVIDE_NUM_SAL)

            {

                togo = "TR_w";

            }

            else if (divide_num == DIVIDE_NUM_HIT)

            {

                togo = "TR_m";

            }

            else if (divide_num == DIVIDE_NUM_STRIKE)

            {

                togo = "TR_s";

            } // end else if

            StartMotion();

            HitArea = "";

            break;

        }

        case "Area_Arm_Left":

        {

            if (divide_num == DIVIDE_NUM_SAL)

            {

                togo = "ML_w";

            }

            else if (divide_num == DIVIDE_NUM_HIT)

            {

                togo = "ML_s";

            }

            else if (divide_num == DIVIDE_NUM_STRIKE)

            {

                togo = "ML_s";

            } // end else if

            StartMotion();

            HitArea = "";

            break;

        }

        case "Area_Arm_Right":

        {

            if (divide_num == DIVIDE_NUM_SAL)

            {

                togo = "MR_w";

            }

            else if (divide_num == DIVIDE_NUM_HIT)

            {

                togo = "MR_s";

            }

            else if (divide_num == DIVIDE_NUM_STRIKE)

            {

                togo = "MR_s";

            } // end else if

            StartMotion();

            HitArea = "";

            break;

        }

        case "Area_Leg_Left":

        {

            if (divide_num == DIVIDE_NUM_SAL)

            {

                togo = "BL_w";

            }

            else if (divide_num == DIVIDE_NUM_HIT)

            {

                togo = "B_m";

            }

            else if (divide_num == DIVIDE_NUM_STRIKE)

            {

                togo = "BL_s";

            } // end else if

            StartMotion();

            HitArea = "";

            break;

        }

        case "Area_Leg_Right":

        {

            if (divide_num == DIVIDE_NUM_SAL)

            {

                togo = "BR_w";

            }

            else if (divide_num == DIVIDE_NUM_HIT)

            {

                togo = "B_m";

            }

            else if (divide_num == DIVIDE_NUM_STRIKE)

            {

                togo = "BR_s";

            } // end else if

            StartMotion();

            HitArea = "";

            break;

        }

    } // End of switch

};

 
by:廖建林(2008-1-13 17:14:00)
----博主回复     
 



共 1 页,1 条记录  

用户名:
密码:
您的评论:



发 表 评 论