当前位置: 首页 > 图文教程 > Flash动画 > Flash动画制作 > Flash教程:纯AS编写蝌蚪摆尾动画效果

Flash动画制作
Flash交互式动画教程:星座查询器的制作
Flash教程:测试AS代码的执行速度
Flash教程:常用短语trace();的使用
Flash教程:if条件语句的用法
FLASH教程:可爱不倒翁动画效果
Flash教程:旋转拖尾文字效果的制作
Flash教程:运用DynamicRegistration类动态改变注册点的使用方法
Flash初学者系列教程:常用工具的使用(一)
Flash 【AS2.0】教程:获取外部按钮方法
Flash教程:10类ActionScript过渡效果演示及代码整理
Flash教程:位图实现形状渐变效果的方法
Flash教程:利用遮罩制作x光机透视效果
Flash鼠绘教程:马蹄莲制作过程
用Flash制作水墨画动画教程
Flash教程:通过实例学习AS(一):火焰的制作
Flash教程:通过实例学习AS(二):小狗追骨头
Flash教程:通过实例学习AS(三):体质测试
Flash教程:菜鸟一起学画画之初级练习一:叶子的绘制
Flash教程:旋转相册的制作
Flash教程:翻书效果的制作

Flash动画制作 中的 Flash教程:纯AS编写蝌蚪摆尾动画效果


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

先看最终效果:

场景里代码

Object.environment = this;
Math.prototype.degrees = function (r)
{
return (r * 180 / 3.141593E+000);
};
maxtents = 3;
this.onEnterFrame = function ()
{
if (!random(30) && tents < maxtents)
{
var nombre = "tent" + String(depth++);
var neo = this.attachMovie("tentacle", nombre, depth);
neo._x = random(600);
neo._y = 370;
neo.theta = 270;
++tents;
} // end if
};
stop ()

MC里的代码

#initclip 1
function TentacleClass()
{
this.numNodes = 27;
this.head = 2 + random(4);
this.girth = 8 + random(12);
this.speedCoefficient = 9.000000E-002 + random(10) / 50;
this.friction = 9.000000E-001 + random(10) / 100;
this.muscleRange = 20 + random(50);
this.muscleFreq = 1.000000E-001 + random(100) / 250;
this.generateNodes();
this.onEnterFrame = this.move;
} // End of the function
TentacleClass.prototype = new MovieClip();
TentacleClass.prototype.generateNodes = function ()
{
this.node = new Array();
var n = 0;
while (n < this.numNodes)
{
var point = {x: 0, y: 0};
this.node.push(point);
++n;
} // end while
};
TentacleClass.prototype.move = function ()
{
this.tv = this.tv + 5.000000E-001 * (Math.random() - Math.random());
this.theta = this.theta + this.tv;
this.tv = this.tv * this.friction;
this.node[0].x = this.head * Math.cos(1.745329E-002 * this.theta);
this.node[0].y = this.head * Math.sin(1.745329E-002 * this.theta);
this.count = this.count + this.muscleFreq;
this.thetaMuscle = this.muscleRange * Math.sin(this.count);
this.node[1].x = -this.head * Math.cos(1.745329E-002 * (this.theta + this.thetaMuscle));
this.node[1].y = -this.head * Math.sin(1.745329E-002 * (this.theta + this.thetaMuscle));
var i = 2;
while (i < this.numNodes)
{
var dx = this.node.x - this.node[i - 2].x;
var dy = this.node.y - this.node[i - 2].y;
var d = Math.sqrt(dx * dx + dy * dy);
this.node.x = this.node[i - 1].x + dx * this.girth / d;
this.node.y = this.node[i - 1].y + dy * this.girth / d;
if (i == 2)
{
this._x = this._x - dx * this.speedCoefficient;
this._y = this._y - dy * this.speedCoefficient;
if (this._x + this._width < 0 || this._x - this._width > 600 || this._y + this._height < 0 || this._y - this._height > 400)
{
--Object.environment.tents;
this.removeMovieClip();
} // end if
} // end if
++i;
} // end while
this.clear();
this.moveTo(this.node[1].x, this.node[1].y);
var i = 2;
while (i < this.numNodes)
{
this.lineStyle(int(this.numNodes - i) * (this.numNodes - i) / 20, 16777215, 100);
this.lineTo(this.node.x, this.node.y);
++i;
} // end while
};
Object.registerClass("tentacle", TentacleClass);
#endinitclip