·您的位置: 首页 » 资源教程 » 创意设计 » Flash » Flash游戏制作:点击可弹动的小球

Flash游戏制作:点击可弹动的小球

类别: Flash教程  评论数:0 总得分:0
  新年将到,在这里先向大家拜个早年,祝大家在鸡年里,flash的水平节节高。 好,现在进入正题,大家先看一下效果。

« Full Screen »


  源文件下载(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;
};



  注:此例仅供学习使用,请勿用于商业用途!
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1