仨个小球一动画 |
| 作者:佚名 来源:闪吧 作者: a32918 更新:2007-1-13 20:46:22 错误报告 我要投稿 |
点击浏览该文件 主要源码:
stop();
//---将整个影片遮照,免得元件跑到外头了 clear(); createEmptyMovieClip("line0", 999); with (line0) { //画整个动画大小的矩形,用它来遮照 lineStyle(1, 0x66FFFF, 100); beginFill(0xFF6600, 100); moveTo(0, 0); lineTo(Stage.width, 0); lineTo(Stage.width, Stage.height); lineTo(0, Stage.height); endFill(); } _root.setMask(_root.line0);
//---影片夹子响应鼠标经过的震动效果 MovieClip.prototype.shockto = function(thename, they, myx, myy) { //扩展影片夹子的属性函数 var thex = 0; var they = 0; var height = this._y-they; this.onEnterFrame = function() { if (this.hitTest(_level0._xmouse, _level0._ymouse)) { //侦测鼠标是否移至影片夹子上
mydistance = (this._x-myx)*(this._x-myx); mydistance += (this._y-myy)*(this._y-myy); //这两句实际上是用变量记录鼠标与(myx,myy)点的距离,即距离公式:c平方=a平方+b平方。
if (mydistance<100) { //其实mydistance应该再开平方根的,考虑到运算耗费资源,就直接用了 //管理响应鼠标事件,当执行事件过程中,鼠标离中心点太远就不能拖动(如果没有这限制会很乱,大家可试试)。
this.startDrag(lock); this._xscale = this._yscale=100; //_root.mymusic.gotoAndPlay(1); } else { this.stopDrag(); //停止拖动,执行下面的复位代码 } } _root[thename+"_s"]._x = this._x; //这两句控制每个影片夹子下面的阴影位置和大小 _root[thename+"_s"]._xscale = _root[thename+"_s"]._yscale=100-(this._y-they)/height*100; //位置越高阴影越小 thex = (myx-this._x)*0.8+thex*0.7; //惯性震动代码 they = (myy-this._y)*0.6+they*0.7; //惯性震动代码 this._x += thex; //惯性震动代码 this._y += they; //惯性震动代码 this._xscale = thex+70; this._yscale = they+70; //将影片夹子的x,y缩放大小与震动的距离挂钩,效果更好。
}; };
MovieClip.prototype.fall = function(thename, they, myx, myy) { //模拟球在重力下下落并以they为水平线作弹跳运动 var v = 0; var j = 9; var height = this._y-they; this.onEnterFrame = function() { _root[thename+"_s"]._y = they+60; //影片夹子的阴影位置控制 _root[thename+"_s"]._x = this._x; //影片夹子的阴影位置控制 _root[thename+"_s"]._xscale = _root[thename+"_s"]._yscale=_root[thename+"_s"]._alpha=100-(this._y-they)/height*100; //影片夹子的大小、透明度控制 if (this._y<they) { //重力下落效果实现,they的值相当于地平线,当this._y等于they就反弹,即将速度反相
v += j; this._y += v; } else { if (j>40) { //当弹跳幅度太小就停止弹跳,并执行下一步的归位并响应鼠标事件(shockto函数,上面写的扩展函数)
delete this.onEnterFrame; this.shockto(thename, they, myx, myy); } j = 1.5*j; //j为震动幅度变化监测值,也在每次震动时作些衰减调整
v = -v; //到预设水平线值,速度变相,实现弹跳效果 _root.hitmusic.gotoAndPlay(1); //放相应的声音 this._y = they-1; //为了回到this._y<they的状态而为之 } }; }; _root.onEnterFrame = function() { //不断画线连接各影片夹子 createEmptyMovieClip("line", 1); ball1.swapDepths(2); //为了让线被前面的球挡住一部分,要不然就不像了,可以试试就知道了
ball3.swapDepths(3); //同上 line.lineStyle(1, 0x66FFFF, 100); line.moveTo(ball1._x, ball1._y); line.lineTo(ball2._x, ball2._y); line.lineTo(ball3._x, ball3._y); line.lineTo(ball1._x, ball1._y); };
ball1.fall("ball1", 200, 100, 120); //大功告成,将每个夹子都赋上功能,美美地调用一番,嘿嘿。。。 ball2.fall("ball2", 150, 200, 80); //同上 ball3.fall("ball3", 190, 400, 150); //同上
|
|
| 文章录入:skyuu 责任编辑:skyuu |
|
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |