当前位置: 首页 > 图文教程 > Flash动画 > Flash动画制作 > Flash游戏制作基础:跟随鼠标的曲线

Flash动画制作
Flash鼠标跟随教程:点蜡烛
Flash教程:无AS下雪动画效果
flash绘画教程:绘制矢量人物
flash8教程:绘制中国风荷塘风景
flash8绘画教程:绘制逼真青翠竹林
FLASH翻译教程:绘制逼真奥迪轿车全过程
Flash8 教程:AS打造光影变换动画效果
Flash教程:AS数学课件—推导三角形面积
Flash教程:简单制作图形变换效果
Flash AS教程:用AS3 两招提取标记语言里的内容
Flash教程:教你表达动画人物走路动作的技巧
Flash教程:用AS打造小球自由运动和碰撞检测的动画
Flash初级教程:介绍两种按钮控制小球左右滚动的写法
Flash教程:教你制作弹力球小游戏
Flash新手教程:一个简单的遮照
Flash 8教程: 制作模糊遮罩效果细析
Flash教程:真人秀眼睛转动教程
Flash教程:用填充变形工具创建不间断滚动图片教程
Flash教程:用AS简单打造下雪效果
Flash教程:用AS打造漂亮线条效果

Flash动画制作 中的 Flash游戏制作基础:跟随鼠标的曲线


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-22   浏览: 73 ::
收藏到网摘: n/a

Flash游戏制作基础,跟随鼠标的曲线,曲线和其它物体之间进行碰撞检测。

友情提示:文章末尾提供Fla源文件的下载。

首先按Ctrl+J修改属性。

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

创建一个MC,如下图。是放大到800%的效果。

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

然后直接使用鼠标跟随,下面代码直接放到第一帧,创建轨迹。

 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    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        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设置如下,做一面墙来检测碰撞。

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

添加一个物体,来实验碰撞检测。添加如下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    nodes[x] = {x:the_head._x, y:the_head._y};
}
the_head.onEnterFrame = function() {
    this._x = _root._xmouse;
    this._y = _root._ymouse;