Flash AS实现的蝌蚪摆尾动画的教程

所属分类: 媒体动画 / Flash教程 阅读数: 94
收藏 0 赞 0 分享
本例介绍使用Flash的AS编写蝌蚪摆尾动画效果,希望朋友们喜欢~~
 

 
场景里代码

复制代码
代码如下:

  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 ()

#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
更多精彩内容其他人还在看

Flash AS 入门 为“关键帧”添加动作

这篇文章主要是介绍flash as编程中,为关键帧添加动作的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

Flash AS 入门 为“按钮”添加鼠标事件

这一节将学习为按钮添加鼠标事件来控制动画的播放状态和控制影片剪辑的播放,实现简单的交互
收藏 0 赞 0 分享

Flash AS 入门 为“影片剪辑”添加鼠标事件

这一节将用上一节学习过的语句,在影片剪辑上添加动作来控制主场景时间轴以及影片剪辑自身的播放
收藏 0 赞 0 分享

Flash AS 入门 “影片剪辑”属性调整及路径解析

本节应掌握的知识要点①影片剪辑属性调整;②相对路径、绝对路径的应用;③赋值运算符“=”应用;④了解算术组合赋值运算符“+=”、“-=”、“*=”、“/=”。
收藏 0 赞 0 分享

Flash AS 入门 条件判断语句 if、else使用介绍

条件判断语句在flash中是实用性很强、使用也很频繁的语句,这一节将学习条件判断语句“if、else”以及“trace”语句的应用
收藏 0 赞 0 分享

Flash AS 入门 duplicateMovieClip和removeMovieClip应用

本节应掌握的知识要点①duplicateMovieClip和removeMovieClip应用;②_visible属性应用;③数组应用
收藏 0 赞 0 分享

Flash AS 入门 “for”循环语句应用

本节应掌握的知识要点①for循环应用;②nextFrame()、prevFrame()动作应用;③层深度的进一步理解
收藏 0 赞 0 分享

Flash AS 入门 鼠标跟随的应用实现

本节应掌握的知识要点① startDrag和stopDrag应用;②with 语句应用
收藏 0 赞 0 分享

Flash AS 入门 onClipEvent()事件处理函数

本节应掌握的知识要点① onClipEvent()应用;②_xmouse 属性;③int函数应用
收藏 0 赞 0 分享

Flash AS 实例进阶 循环按钮

按钮触发事件发生后有可执行的两个以上的命令。②由条件判断语句来执行不同的命令。③按钮的外观要有相应的切换(如果需要)
收藏 0 赞 0 分享
查看更多