跟随鼠标的弹性球运动小游戏(Flash CS3)
作者:闪电儿 类型:转载 来源:网页教学网
用Flash CS3的AS制作跟随鼠标弹性小游戏,主要是练习AS的使用。
先看演示:
源文件下载:
弹性小球运动.rar
修改文档属性。

首先建立4个小的电影剪辑元件,分别设置如下:




回到主场景中加入如下代码:
attachMovie("newmouse","newmouse",_root.getNextHighestDepth());
attachMovie("circle","circle",_root.getNextHighestDepth(),{_x:250, _y:200});
attachMovie("crosshair","crosshair",_root.getNextHighestDepth());
attachMovie("ball","ball",_root.getNextHighestDepth());
Mouse.hide();
friction = 0.9;
speed_scale = 0.1;
xspeed = 0;
yspeed = 0;
newmouse.onEnterFrame = function() {
this._x = _root._xmouse;
this._y = _root._ymouse;
};
crosshair.onEnterFrame = function() {
this._x = _root._xmouse;
this._y = _root._ymouse;
dist_x = this._x-circle._x;
dist_y = this._y-circle._y;
distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
if (distance>45) {
angle = Math.atan2(dist_y, dist_x);
this._x = 250+45*Math.cos(angle);
this._y = 200+45*Math.sin(angle);
}
};
ball.onEnterFrame = function() {
dist_x = (crosshair._x-this._x)*speed_scale;
dist_y = (crosshair._y-this._y)*speed_scale;
xspeed += dist_x;
yspeed += dist_y;
xspeed *= friction;
yspeed *= friction;
this._x += xspeed;
this._y += yspeed;
};
attachMovie("circle","circle",_root.getNextHighestDepth(),{_x:250, _y:200});
attachMovie("crosshair","crosshair",_root.getNextHighestDepth());
attachMovie("ball","ball",_root.getNextHighestDepth());
Mouse.hide();
friction = 0.9;
speed_scale = 0.1;
xspeed = 0;
yspeed = 0;
newmouse.onEnterFrame = function() {
this._x = _root._xmouse;
this._y = _root._ymouse;
};
crosshair.onEnterFrame = function() {
this._x = _root._xmouse;
this._y = _root._ymouse;
dist_x = this._x-circle._x;
dist_y = this._y-circle._y;
distance = Math.sqrt(dist_x*dist_x+dist_y*dist_y);
if (distance>45) {
angle = Math.atan2(dist_y, dist_x);
this._x = 250+45*Math.cos(angle);
this._y = 200+45*Math.sin(angle);
}
};
ball.onEnterFrame = function() {
dist_x = (crosshair._x-this._x)*speed_scale;
dist_y = (crosshair._y-this._y)*speed_scale;
xspeed += dist_x;
yspeed += dist_y;
xspeed *= friction;
yspeed *= friction;
this._x += xspeed;
this._y += yspeed;
};
按Ctrl+Enter测试影片吧!
责任编辑:silvia 时间:2007年9月27日
- 上一篇:
- 分镜的赏析与运用_Reload 分镜 新版教
- 下一篇:
- flash分身效果
- 没有相关教材
- 最近更新
