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

所属分类: 媒体动画 / Flash教程 阅读数: 193
收藏 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 入门 as自定义函数

如果有一个功能或者一段代码要经常使用,则可以把它写成自定义函数,在用到的时候调用它。使用函数是为了简化编程的负担,减少代码量和提高效率
收藏 0 赞 0 分享

Flash AS 入门教程 事件处理函数及画线语句

我们学过在按扭或者影片剪辑上添加事件,这些事件也可以很方便地写在帧上,使用起来比较方便,有时也能起到简化脚本的作用。这些写在帧上的事件在软件中是位置是内置类影片MovieClip事件
收藏 0 赞 0 分享

Flash AS 入门教程 圆和椭圆函数的应用

Flash AS 入门教程 圆和椭圆函数的应用,需要的朋友可以参考下
收藏 0 赞 0 分享

Flash AS 入门教程 碰撞检测hitTest函数

hitTest函数是用来检测两个物体或目标是否重叠和相交,如果相交或重叠,就执行相应的动作,这对于我们做一些互动的动画和游戏是非常有用。比如在做点鞭炮、射击等的动画时,就可以用hitTest的方法
收藏 0 赞 0 分享

Flash AS 入门教程 乱数排列(随机数)方法

选取不重复的随机数(或者叫乱数),在flash的编程中经常都会用到,这里简单介绍下,需要的朋友可以参考下
收藏 0 赞 0 分享

Flash AS 入门教程 setInterval函数应用举例

setInterval动作的作用是在播放动画的时,每隔一定时间就调用函数,方法或对象
收藏 0 赞 0 分享

Flash AS 入门教程 三个实例讲解

画正玄图象,由外部输入控制起点横坐标、震幅和跨度,把文字和下面的mc的位置都分别作任意的排列
收藏 0 赞 0 分享

Flash AS 入门教程 多维数组和双重循环使用介绍

我们用到了一个mc对另外一个mc的遮罩。它的原理是:在作为遮罩片的mc中,复制部分小方块mc,并且随机放置这些小方块mc。当然,这样的随机放置不是任意的,必须满足两个条件:放置的位置不重复;能够完全遮罩图形
收藏 0 赞 0 分享

Flash AS 入门教程 loadMovie应用举例 多画面与画中画实现

加载外部文件命令loadMovie()可以在播放 SWF 文件的同时,将外部的 SWF 文件或 JPEG 文件加载到 Flash Player 中,使您可以同时显示几个 SWF 文件,或者在几个SWF 文件之间切换
收藏 0 赞 0 分享

Flash AS 入门教程 调入外部文本和加载外部mp3文件

在Flash制作时,有时候为了更灵活、方便,我们可以直接调入外部文本文件。要修改时只要修改记事本里的文本并保存,无需打开Flash源文件对其修改
收藏 0 赞 0 分享
查看更多