新年将到,在这里先向大家拜个早年,祝大家在鸡年里,flash的水平节节高。 好,现在进入正题,大家先看一下效果。
源文件下载(zip压缩文件,6K)。 另外大家可以看一看一个曾经很流行的成品游戏:《是男人就点一百下》 这个是简单的弹性效果的延伸。主体基本全是用as来实现的。下面讲解一下制作过程。 1. 在flash中新一个MC,在此MC上分别建三层来放圆,按钮,还有as命令。如图所示: 在此,as命令为:stop();
2. 回到主场景,在第一帧上加入as命令。_root.createEmptyMovieClip("ball", 69); //创建一个空的MC,命名为ball ball.lineStyle(60, 0xFFFFFF, 100); //设定ball的线条样式为60粗,白色,alpha为100 ball.lineTo(1, 0); //使用当前线条样式从当前绘画位置向 (x, y) 绘制线条 vars = new Array("xspeed", "yspeed", "leftedge", "rightedge", "bottomedge", "gravity", "friction", "bounce", "widthBall", "heightBall", "maxaffiche", "forceDribble", 6, 0, -30, (Stage.width)+(_root.ball._width/4), (Stage.height)+(_root.ball._width/4), 2.4, 0.982, 0.7, _root.ball._width/2, _root.ball._height/2, 10, 22); //建立数组 for (i=0; i<(vars.length/2); i++) { this[vars[i]] = vars[i+(vars.length/2)]; } //初始数组的取值 //----------------------------------------- //ball点击时,改变数组中xspeed,yspeed的值 ball.onPress = function() { _root.xspeed -= (_root._xmouse-this._x)/2; _root.yspeed = -_root.forceDribble; }; //--------------------------------------- //设置ball的反弹, ball.onEnterFrame = function() { this._x = this._x+xspeed; this._y = this._y+yspeed; if (this._x+widthBall>rightedge || this._x-widthBall xspeed = -xspeed*bounce; this._x = (this._x+widthBall>rightedge) ? (rightedge-widthBall) : (leftedge+widthBall); } if (this._y+heightBall>bottomedge) { yspeed = -yspeed*bounce; this._y = bottomedge-heightBall; } yspeed = (yspeed*friction)+gravity; xspeed = xspeed*friction; };
注:此例仅供学习使用,请勿用于商业用途!