当前位置: 移动技术网 > IT编程>UI设计>设计软件 > Flash AS实现的蝌蚪摆尾动画的教程

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

2019年03月21日  | 移动技术网IT编程  | 我要评论
本例介绍使用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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网