13、在“Action”层的第2帧插入关键帧,在第7帧插入帧,此时主场景中的层应该如图4所示。点击“Action”层的第2帧,在此帧的Action Script面板上面添加语句下所示。

| 以下是引用片段: stop(); VEL_SAL_LIMIT = 70; // 注释1 VEL_HIT_LIMIT = 180; DIVIDE_NUM_STRIKE = 30; DIVIDE_NUM_HIT = 24; DIVIDE_NUM_SAL = 12; Area_Head_Left._visible = false; // 注释2 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.0; // 注释3 cursor_old_y = 0.0; cursor_new_x = 0.0; cursor_new_y = 0.0; cursor_velocity = 0.0; HitArea = ""; divide_num = 1; xpoint_array = new Array(); ypoint_array = new Array(); init = false; function CalVelocity() { // 注释4 cursor_old_x = cursor_new_x; cursor_old_y = cursor_new_y; cursor_new_x = int(this._xmouse); cursor_new_y = int(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))); } function CalPoints() { // 注释5 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; } xdivide = (cursor_new_x-cursor_old_x)/divide_num; ydivide = (cursor_new_y-cursor_old_y)/divide_num; for (i=0; i function HitCheck() { // 注释6 for (i=0; icursor_old_x) { HitArea = "Area_Head_Left"; break; } } } else 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_Arm_Left"; break; } } } else 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_Leg_Left"; break; } } } else 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] function StartMotion() { // 注释7 _root.Motion_all.gotoAndPlay(togo); } onEnterFrame = function () { // 注释8 CalVelocity(); CalPoints(); HitCheck(); if (!init) { HitArea = ""; init = true; } 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"; } 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"; } 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"; } 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"; } 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"; } 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"; } StartMotion(); HitArea = ""; break; } } |
注释1:定义一些变量,分别用来判断鼠标是否以比较慢、中等、比较快的速度划过对象。
注释2:隐藏用来捕捉鼠标动作的对象。
注释3:初始化鼠标的参数。
注释4:这个函数是用来捕捉鼠标划过的速度和划过的位置。
注释5:这个函数是用来判断鼠标划过地速度,分别为强、中、弱。
注释6:这个函数是判断鼠标划过的位置,分别对应场景中的对象的头、手、脚。
注释7:在这个函数中,播放鼠标动作所触发的相应场景。
注释8:这是整个场景的启动函数,不断的循环,不断地对鼠标动作产生响应。
三、小结
总的来说,就是让场景中的对象响应鼠标动作,相应的鼠标动作触发播放相应的Movie Clip。其中Movie Clip的制作好坏,对整体效果的影响是很大的,值得用心去做好Movie Clip。
下载本例源文件(zip压缩文件,468K)
| 共分4页 [1] [2] [3] [4] |
关于网站 | 客服中心 | 服务条款 | 友情链接 | 广告联系 | 本站历程 | 网站导航
吉ICP备05000107号