flash三角函数实现炮弹发出动画效果

修改
鏉ユ簮: junjun 浏览 4213 日期 2011-10-22 0

   首先建两个图层,画一个炮和一个炮弹,做成movieclip给炮起名叫spaceship,图库的炮弹上右击,选linkage,选第一项,并起名叫projectile。

  把炮弹托到舞台外面,一定要托出来,要不就不好用(因为你在linkage时没有选第三项)。

  下面是主要的:再建一个图层,在这两个图层的上面。

  speed = 4; // 是炮弹移动的速度

  depth = 0; // 复制的炮弹深度

  nose = 50; // (这个值跟你的炮的宽度而定)

  _root.onmousemove = function() {

  updateafterevent();

  xdiff = _root._xmouse-spaceship._x;

  ydiff = _root._ymouse-spaceship._y;

  angle = math.atan2(ydiff, xdiff);

  angle = angle*180/math.pi;

  spaceship._rotation = angle;

  };

  //上面主要是取角度

  _root.onmousedown = function() {

  angle = spaceship._rotation;

  angle = angle*math.pi/180;

  ++depth;

  name = "projectile"+depth;

  _root.attachmovie("projectile", name, depth);//复制炮弹

  _root[name]._x = spaceship._x+nose*math.cos(angle);

  _root[name]._y = spaceship._y+nose*math.sin(angle);// 炮弹发出的位置

  _root[name].xmov = speed*math.cos(angle);

  _root[name].ymov = speed*math.sin(angle); // 炮弹发出的角度

  _root[name].onenterframe = function() {

  this._x += this.xmov;

  this._y += this.ymov;

  };//炮弹移动

  };

  shoot.fla (44.0k)

  完

评论

{{ username ? username.charAt(0).toUpperCase() : '?' }}
Ctrl+Enter 发布
{{ (c.username || c.author_name || '?').charAt(0).toUpperCase() }}
{{ c.username || c.author_name }} {{ Utils.formatDate(c.created_at) }}