欢迎来到天天文库
浏览记录
ID:61766693
大小:55.00 KB
页数:5页
时间:2021-03-19
《Flash游戏制作基础:跟随鼠标的曲线.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Flash游戏制作基础:跟随鼠标的曲线作者:闪电儿 类型:转载 来源:网页教学网 Flash游戏制作基础,跟随鼠标的曲线,曲线和其它物体之间进行碰撞检测。网页教学网友情提示文章末尾提供Fla源文件的下载。首先按Ctrl+J修改属性。创建一个MC,如下图。是放大到800%的效果。然后直接使用鼠标跟随,下面代码直接放到第一帧,创建轨迹。tail_len = 2;tail_nodes = 100;nodes = new Array();_root.attachMovie("the_head"
2、, "the_head", 1, {_x:250, _y:200});_root.createEmptyMovieClip("the_tail", 2);for (x=1; x3、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; x4、.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设置如下,做一面墙来检测碰撞。5、添加一个物体,来实验碰撞检测。添加如下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=6、1; x7、, the_head._y); nodes[0] = {x:the_head._x, y:the_head._y}; for (var x = 1; x8、s_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)源文件下载: 曲线.
3、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; x4、.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设置如下,做一面墙来检测碰撞。5、添加一个物体,来实验碰撞检测。添加如下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=6、1; x7、, the_head._y); nodes[0] = {x:the_head._x, y:the_head._y}; for (var x = 1; x8、s_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)源文件下载: 曲线.
4、.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设置如下,做一面墙来检测碰撞。
5、添加一个物体,来实验碰撞检测。添加如下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=
6、1; x7、, the_head._y); nodes[0] = {x:the_head._x, y:the_head._y}; for (var x = 1; x8、s_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)源文件下载: 曲线.
7、, the_head._y); nodes[0] = {x:the_head._x, y:the_head._y}; for (var x = 1; x8、s_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)源文件下载: 曲线.
8、s_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)源文件下载: 曲线.
此文档下载收益归作者所有