1  /  2  页   12 跳转 查看:1764

标题: FLASH模拟球的运动

FLASH模拟球的运动

[FLASH=400,300]http://bbs.flash8.net/bbs/UploadFile/2005-10/20051012182425614.swf[/FLASH]

代码如下:

//y轴方向的速度 
var ymov:Number = 0;
//X轴方向的速度

var xmov:Number = 0;
//重力加速度
var gravity:Number = 0.88;
//复制一个透明的球,让这个球跟随原球,利用两球的距离计算球的速度
duplicateMovieClip("ball", "ball_follow", 1);
ball_follow._alpha = 0;
_root.attachMovie("hand", "Hand", 2);
Hand.startDrag(true);
_root.onEnterFrame = function() {
Mouse.hide();
Shadow._x = ball._x-11;
//用缓冲的方式设置复制的球跟随原球
ball_follow._x += (ball._x-ball_follow._x)*0.2;
ball_follow._y += (ball._y-ball_follow._y)*0.2;
//设置影子的透明度和宽度
Shadow._alpha = 100-(Shadow._y-ball._y);
Shadow._width = 59+(Shadow._y-ball._y);
ball.onPress = function() {
  Hand.gotoAndStop(2);
  x = ball._x-_xmouse;
  y = ball._y-_ymouse;
  leave = true;
};
ball.onRelease = function() {
  Release();
};
ball.onReleaseOutside = function() {
  Release();
};
//设置球的反弹
if (leave) {
  ball._x = _xmouse+x;
  ball._y = _ymouse+y;
} else {
  ymov += gravity;
  ball._y += ymov;
  ball._x += xmov;
  xmov *= 0.98;
}
//设置球与墙碰撞后的结果
if (ball._y>=Shadow._y-ball._height/2) {
  ball._y = Shadow._y-ball._height/2;
  ymov *= -0.85;
}
if (ball._x<ball._width/2) {
  ball._x = ball._width/2;
  xmov = -xmov;
}
if (ball._x>800-ball._width/2) {
  ball._x = 800-ball._width/2;
  xmov = -xmov;
}
};
function Release(){
Hand.gotoAndStop(1);
  xmov = (ball._x-ball_follow._x)/3;
  ymov = (ball._y-ball_follow._y)/5;
  leave = false;
}
引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 

Re:FLASH模拟球的运动

引用
 
1  /  2  页   12 跳转

版权所有 灵动原创FLASH游戏中心   Sitemap

Powered by Discuz!NT 2.0.1214    Copyright © 2001-2008 Comsenz Inc.
Processed in 0.03125 second(s) , 4 queries. 苏ICP备05047165号
返顶部