用户ID :  密码 : 

登 录

注 册

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

我的资料

moo

博客信息

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

最新公告

又开始写博啦...

我的日历

最新评论

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

RSS

首页 -> 我的评论
2008-01-14

学习学习~~~嘿

2008-01-03

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

};

共 1 页,3 条记录