专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Flash教程 » flash特效:用Flash AS编写蝌蚪摆尾特效动画 »正文

flash特效:用Flash AS编写蝌蚪摆尾特效动画

来源: 发布时间:星期五, 2009年1月23日 浏览:23次 评论:0
  本文中我们用Flash AS代码来编写个蝌蚪自由摆尾游动动画  场景里代码:

Object.environment = this;
Math.prototype.degrees = function (r)
{
   (r * 180 / 3.141593E+000);
};
maxtents = 3;
this.onEnterFrame = function
{
   (!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
};
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 = MovieClip;
TentacleClass.prototype.generateNodes = function
{
  this.node = Array;
  var n = 0;
  while (n < this.numNodes)
  {
    var po = {x: 0, y: 0};
    this.node.push(po);
    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;
     (i 2)
    {
      this._x = this._x - dx * this.speedCoefficient;
      this._y = this._y - dy * this.speedCoefficient;
       (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
    } // end
    i;
  } // end while
  this.clear;
  this.moveTo(this.node[1].x, this.node[1].y);
  var i = 2;
  while (i < this.numNodes)
  {
    this.lineStyle((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


1

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: