点击浏览该文件 制作过程: 1. 创建定义物体轮廓的控制点对象
在场景创建一个名为refer的影片剪辑,不对它做任何剪辑(空的)。
2.创建物体对象
(1)在场景编辑状态下创建一个名为lemonrefer的影片剪辑。不做任何编辑,退出影片剪辑lemonrefer.
(2).在场景1下创建一个名为lemon的mc
(3)进入lemon的编辑状态,将第一层名为lemon.选择层其第一帧,导入柠檬的矢量图文件。
(4)使图片位于舞台的中央,然后ctrl+b,打散。如图。
(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){
var c=0;
var xs=0;
var ys=0;
var diff=0;
var hitFloorX=0;
var hitWallY=0;
//对所有在perim影片剪辑中的refer剪辑
for (i in this.perim) {
//将p.x和p.y设置成refer的x,y坐标
this.perim.localToGlobal(p={x:this.perim[i]._x,y:this.perim[i]._y})
//如果不在舞台内,而在舞台的下方
if (p.y > h) {
//当refer碰撞时设置其x坐标为hitFloorX
hitFloorX = p.x
//将影片剪辑放回舞台内。
this._y -= p.y - h;
}
//如果不在舞台内,而在舞台的右方
if (p.x > w) {
将refer碰撞墙壁点设为hitWallY
hitWallY = p.y;
//dy<0意味着剪辑正在缓慢的向上移动,剪辑向上运动一半
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=碰撞的中心偏移量
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;
}
}
ASSetPropFlags(MovieClip.prototype, "col", 1);
_global.gcGravity = 15;
_global.gcDamping = 0.5;
_global.gcStageHeight = 300;
_global.gcStageWidth = 400;
aClips = ["mclemon"];
for (i in aClips) {
thisClip = this[aClips[i]];
thisClip._x = random(gcStageWidth);
thisClip._y = random(gcStageHeight);
thisClip.onPress = function() {
this.r = 0;
this.startDrag();
this.oX = _root._xmouse;
this.pr = true;
};
thisClip.onRelease = thisClip.onReleaseOutside = function() {
this.stopDrag();
this.pr = false;
};
thisClip.onEnterFrame = function() {
this.col(gcStageWidth, gcStageHeight, gcDamping);
//ox是剪辑在前一帧中的X坐标
this.ox = this.x;
this.oy = this.y;
this.x = this._x;
this.y = this._y;
//如果单击了物体,则根据它在前一帧的位置来设置其在X轴方向的差值,
if (this.pr) {
this.dx = (this.x-this.ox)*7;
this.dy = (this.y-this.oy)*7;
} else {
//如果释放鼠标,由于重力的影响要加上dy的值
共有 0 位网友发表了评论,得分 0 分,平均 0 分 查看完整评论