Flash游戲制作基礎(chǔ):跟隨鼠標(biāo)的曲線_Flash教程
推薦:用Flash AS簡(jiǎn)單制作可以任意拖動(dòng)的四邊形用FlashActionscript簡(jiǎn)單制作可以任意拖動(dòng)的四邊形,是制作游戲的一個(gè)基礎(chǔ)程序。打開Flash,首先將屬性改為30fps然后新建立一個(gè)組建laser,設(shè)置效果如下。然
Flash游戲制作基礎(chǔ),跟隨鼠標(biāo)的曲線,曲線和其它物體之間進(jìn)行碰撞檢測(cè)。友情提示文章末尾提供Fla源文件的下載。
首先按Ctrl J修改屬性。

創(chuàng)建一個(gè)MC,如下圖。是放大到800%的效果。

然后直接使用鼠標(biāo)跟隨,下面代碼直接放到第一幀,創(chuàng)建軌跡。
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);
}
};
演示效果如下。
然后再建立一個(gè)MC設(shè)置如下,做一面墻來(lái)檢測(cè)碰撞。

添加一個(gè)物體,來(lái)實(shí)驗(yàn)碰撞檢測(cè)。添加如下Action到主場(chǎng)景第一幀。
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);
}
};
效果如下。
分享:用Flash制作課件中的倒計(jì)時(shí)動(dòng)畫效果入門者寫的教程面向入門者,讓我們一起成為高手吧!本教程得到了終極討厭大師的鼎力幫助,在此謝謝!先看效果(為了方便演示,我把時(shí)間設(shè)置成了10秒鐘的倒計(jì)時(shí)
Flash教程Rss訂閱網(wǎng)站制作教程搜索
Flash教程推薦
猜你也喜歡看這些
- Flash as3.0視頻教程之聲音編程
- Flash CS3動(dòng)畫設(shè)計(jì)入門提高與技巧(光盤).
- Flash 8完美動(dòng)畫設(shè)計(jì)與制作
- 課件\flash的多媒體教程
- Flash8基礎(chǔ)與實(shí)例教程配套光盤
- 中國(guó)閃客原創(chuàng)爬行榜Flash TOP10動(dòng)畫風(fēng)暴 隨書光盤 2CD
- Flash CS3動(dòng)畫制作從新手到高手
- 臺(tái)灣呂聰賢Flash MX視頻教程
- Flash CS3動(dòng)畫制作基礎(chǔ)與提高
- Flash8全實(shí)例學(xué)習(xí)手冊(cè)原書配套光盤
- 相關(guān)鏈接:
- 教程說(shuō)明:
Flash教程-Flash游戲制作基礎(chǔ):跟隨鼠標(biāo)的曲線
。