收藏 分销(赏)

Flash游戏制作基础:跟随鼠标的曲线.doc

上传人:仙人****88 文档编号:11764552 上传时间:2025-08-12 格式:DOC 页数:5 大小:55KB 下载积分:10 金币
下载 相关 举报
Flash游戏制作基础:跟随鼠标的曲线.doc_第1页
第1页 / 共5页
Flash游戏制作基础:跟随鼠标的曲线.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
Flash游戏制作基础:跟随鼠标的曲线 作者:闪电儿   类型:转载   来源:网页教学网    Flash游戏制作基础,跟随鼠标的曲线,曲线和其它物体之间进行碰撞检测。网页教学网友情提示文章末尾提供Fla源文件的下载。 首先按Ctrl+J修改属性。 创建一个MC,如下图。是放大到800%的效果。 然后直接使用鼠标跟随,下面代码直接放到第一帧,创建轨迹。 tail_len = 2; tail_nodes = 100; nodes = new Array(); _root.attachMovie("the_head", "the_head", 1, {_x:250, _y:200}); _root.createEmptyMovieClip("the_tail", 2); for (x=1; x<tail_nodes; x++) {     nodes[x] = {x:the_head._x, y:the_head._y}; } the_head.onEnterFrame = function() {     this._x = _root._xmouse;     this._y = _root._ymouse;     the_tail.clear();     the_tail.lineStyle(2, 0x00ff00);     the_tail.moveTo(the_head._x, the_head._y);     nodes[0] = {x:the_head._x, y:the_head._y};     for (var x = 1; x<tail_nodes-1; ++x) {         rotation = Math.atan2(nodes[x].y-nodes[x-1].y, nodes[x].x-nodes[x-1].x);         pos_x = nodes[x-1].x+tail_len*Math.cos(rotation);         pos_y = nodes[x-1].y+tail_len*Math.sin(rotation);         nodes[x] = {x:pos_x, y:pos_y};         the_tail.lineTo(pos_x, pos_y);     } };  演示效果如下:(图一) 然后再建立一个MC设置如下,做一面墙来检测碰撞。 添加一个物体,来实验碰撞检测。添加如下Action到主场景第一帧: tail_len = 2; tail_nodes = 100; nodes = new Array(); _root.attachMovie("the_head", "the_head", 1, {_x:250, _y:200}); _root.createEmptyMovieClip("the_tail", 2); _root.attachMovie("wall", "wall", 3, {_x:250, _y:200}); for (x=1; x<tail_nodes; x++) {     nodes[x] = {x:the_head._x, y:the_head._y}; } the_head.onEnterFrame = function() {     this._x = _root._xmouse;     this._y = _root._ymouse;     the_tail.clear();     the_tail.lineStyle(2, 0x00ff00);     the_tail.moveTo(the_head._x, the_head._y);     nodes[0] = {x:the_head._x, y:the_head._y};     for (var x = 1; x<tail_nodes-1; ++x) {         rotation = Math.atan2(nodes[x].y-nodes[x-1].y, nodes[x].x-nodes[x-1].x);         pos_x = nodes[x-1].x+tail_len*Math.cos(rotation);         pos_y = nodes[x-1].y+tail_len*Math.sin(rotation);         nodes[x] = {x:pos_x, y:pos_y};         if (wall.hitTest(pos_x, pos_y, true)) {             the_tail.lineStyle(2, 0xff0000);         }         the_tail.lineTo(pos_x, pos_y);     } };  效果如下:(图2) 源文件下载: 曲线.rar
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服