当然先看一下效果来:
点击浏览该文件 制作过程:
1. 创建定义物体轮廓的控制点对象
在场景创建一个名为refer的影片剪辑,不对它做任何剪辑(空的)。
2.创建物体对象
(1)在场景编辑状态下创建一个名为lemonrefer的影片剪辑。不做任何编辑,退出影片剪辑lemonrefer.
(2).在场景1下创建一个名为lemon的mc
(3)进入lemon的编辑状态,将第一层名为lemon.选择层其第一帧,导入柠檬的矢量图文件。
(5)在lemon层上新建一层,名为lemonrefer,在其第一帧中拖入一个lemonrefer的mc,中心对齐舞台中心。
(6)双击lemonrefer实例,进入它的编辑状态,选择第一帧,从库中拖曳mc实例refer,放在lemon的边缘上,直到“包围”它。如图:
(7)退出mc实例lemonrefer,在属性栏中命名为perim.
退出mc实例lemon,完成编辑。
3.在场景中编写AS。
(1)在场景1中,拖入一个lemon实例,在属性栏中命名为mclemon
新建一层,名为as,添加代码: Movieclip.prototype.col = function(w, h, d){ //对所有在perim影片剪辑中的refer剪辑 //将p.x和p.y设置成refer的x,y坐标 //如果不在舞台内,而在舞台的下方 //当refer碰撞时设置其x坐标为hitFloorX //将影片剪辑放回舞台内。 将refer碰撞墙壁点设为hitWallY //dy<0意味着剪辑正在缓慢的向上移动,剪辑向上运动一半 //弹回来 //对到舞台的左面进行同样的处理。 //diff=碰撞的中心偏移量 //如果物体在旋转,则也在其旋转的方向上移动,
//相对于旋转量的移动量 //如果碰撞了墙壁 ASSetPropFlags(MovieClip.prototype, "col", 1);
_global.gcGravity = 15; aClips = ["mclemon"]; thisClip.onPress = function() { thisClip.onEnterFrame = function() { //ox是剪辑在前一帧中的X坐标 //如果单击了物体,则根据它在前一帧的位置来设置其在X轴方向的差值, //如果释放鼠标,由于重力的影响要加上dy的值 //放慢物体的旋转
var c=0;
var xs=0;
var ys=0;
var diff=0;
var hitFloorX=0;
var hitWallY=0;
for (i in this.perim) {
this.perim.localToGlobal(p={x:this.perim[i]._x,y:this.perim[i]._y})
if (p.y > h) {
hitFloorX = p.x
this._y -= p.y - h;
}
//如果不在舞台内,而在舞台的右方
if (p.x > w) {
hitWallY = p.y;
if (this.dy < 0) this.dy *= d;
this._x -= (p.x - w)*3;
}
if (p.x < 0) {
hitWallY = p.y;
if (this.dy < 0) this.dy *= d;
this._x -= p.x*3;
}
ys += p.y;
xs += p.x;
c++; //refer的数量
}
//如果撞到了地面
if(hitFloorX){
diff = (xs/c) - hitFloorX
this.r=(this.r + diff*(this.dy/350))/1.2
this.dy *= -1.4 * d;
this.dx *= d;
this.dx += this.r*2;
}
if (hitWallY) {
diff = (ys/c) - hitWallY;
this.dx *= -1 * d;
}
}
_global.gcDamping = 0.5;
_global.gcStageHeight = 300;
_global.gcStageWidth = 400;
for (i in aClips) {
thisClip = this[aClips[i]];
thisClip._x = random(gcStageWidth);
thisClip._y = random(gcStageHeight);
this.r = 0;
this.startDrag();
this.oX = _root._xmouse;
this.pr = true;
};
thisClip.onRelease = thisClip.onReleaseOutside = function() {
this.stopDrag();
this.pr = false;
};
this.col(gcStageWidth, gcStageHeight, gcDamping);
this.ox = this.x;
this.oy = this.y;
this.x = this._x;
this.y = this._y;
if (this.pr) {
this.dx = (this.x-this.ox)*7;
this.dy = (this.y-this.oy)*7;
} else {
this.dy += gcGravity;
this.x += this.dx/10;
this.y += this.dy/10;
this._x = this.x;
this._y = this.y;
}
this._rotation += this.r;
this.r *= .95;
}
}
点击浏览该文件

