首页  韩国资源  酷站加油  我的展厅  设计名站  古典元素  推荐下载  设计欣赏  每周专访  招募精英  人才专区  网页教程  平面设计  编程开发  设计竞赛
当前位置:首页 > 网页教程 > Flash教程 > 正文
Google
Flash游戏制作基础:跟随鼠标的曲线
来源:网页教学网 作者:闪电儿 2007年07月17日 17:02 网友评论:0条 点击:

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);
    }
}; 

演示效果如下:

/UploadTeach/200707/20070716155357575.swf

然后再建立一个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);
    }
}; 

效果如下:

/UploadTeach/200707/20070716155420348.swf


源文件下载:曲线.rar

上一篇:用Flash AS简单制作可以任意拖动的四边形   下一篇:flash9/flash cs3(as3)通过soap访问Web Services
收藏此页】【打印】【关闭
 相关文章  我要点评
·教你用Photoshop简单打造魔幻曲线
·通过多点绘制光滑曲线
·九个优美腿部曲线的秘密
·用Photoshop曲线去斑
·Photoshop曲线调整图片之三红绿蓝
·Photoshop曲线调整图片的重要四点用途二
·Photoshop曲线调整图片的重要四点用途
·巧用Photoshop曲线纠正照片偏色技巧

免责声明:本站刊载此文不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。对本文有任何异议,请联络:68design#163.com
转载要求:作者及来源信息必需保留。转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印。



关于我们 | 在线反馈 | 广告报价 | 友情链接 | 联系我们 | 免责声明 | 在线投稿 | 网站地图
Copyright © 2003-2007 68design.net, All Rights Reserve 【找网页设计师,当然上网页设计师联盟】