Flash技巧——重力球制作


在场景中做一小球按F8设为按钮 
回到主场景再次按F8,在按钮中写as: 
on (press) { 
dragging = true; 
startDrag (this, true); 

on (release, releaseOutside) { 
dragging = false; 
stopDrag ();} 
在第一帧写as: 
movheight = 380; 
mvwidth =550; 
在mc中写as: 

onClipEvent (load) { 
gravity = 9;//重力加速度 
bounce = 0.8;//反弹是原来的8/10 
radius = this._width/2;//小球半径(用来判断小球反弹的位置) 

onClipEvent (enterFrame) { //每一帧都执行一次 
oldx = x;//旧的小球x坐标(第一次运行时不被执行) 
oldy = y;//旧的小球y坐标 
x = this._x;//小球x坐标 
y = this._y;//小球y坐标 
if (dragging) {//判断是否按下鼠标 
vx = (x-oldx)*10;//小球现在x坐标减上一次的x坐标得出运动的距离,再扩大十倍 
vy = (y-oldy)*10;//小球现在y坐标减上一次的y坐标得出运动的距离,再扩大十倍 
} else {//释放时 
vy += gravity;//vy加重力加速度赋给vy 
x += (vx/10);//返回原来的x值 
y += (vy/10);//返回原来的y值 
if (y<radius) {//判断是不是到达上边 
y = radius;//小球的y坐标等于小球半径值的y坐标 
vx *= bounce;//乘以反弹值 
vy *= -bounce; 

if (y>(_root.movheight-radius)) {//判断是不是到达底边 
y = _root.movheight-radius; 
vx *= bounce; 
vy *= -bounce;(同上) 

if (x<radius) {//判断是不是到达左边 
x = radius; 
vx *= -bounce; 
vy *= bounce; 

if (x>(_root.movwidth-radius)) {//判断是不是到达右边 
x = _root.movwidth-radius; 
vx *= -bounce; 
vy *= bounce; 

setProperty (this, _x, x);//把变量x赋给小球 
setProperty (this, _y, y);//把变量y赋给小球 

文章评级:★★★★★☆☆☆☆ 发表者:{佚名(127.0.0.*)} 3-29 [ 0]

 分享到:
 
 
相关文章:
我是:
本站注册用户
用户名: 密码:
非本站注册用户
我来评论:

评论字数在2000字以内。评论即可得2分,评论被采用后,根据评级可得到相应的积分和智慧果。
比如:评论评级为5,可得50分和5个智慧果。

 

 
 
 
 
 
 
































 

© 版权所有  2001-2024 知识网站
Copyright (C) 2001-2024 allzhishi.com All rights reserved
联系我们 — 电话:15973023232  微信:zhishizaixian  ICP备案号:湘ICP备08003211号-4