给你做了个demo 看看吧主场景:800×600小球:30×30小球实例命名为ball_mc在第一帧放以下代码:
var xSpeed:Number = 0;var ySpeed:Number = 0;var g:Number = 1;//重力常量var upSpeed;var runStatus = -1;// 1为上升过程 -1为下落过程function runBall() {ySpeed = 0;ball_mc.onEnterFrame = function() {
if (runStatus == -1) {if (ball_mc._y<400) {ySpeed += g;ball_mc._y = ball_mc._y+ySpeed;//向下为正方向} else {//delete ball_mc.onEnterFrame;upSpeed = ySpeed;ySpeed = 0;runStatus = 1;}}if (runStatus == 1) {if (upSpeed>0) {upSpeed -= g;trace(upSpeed);ball_mc._y = ball_mc._y-upSpeed;} else {runStatus = -1;}}};}//-------------------------拖拽小球----------------------------ball_mc.onPress = function() {_root.ball_mc.startDrag();delete ball_mc.onEnterFrame;};ball_mc.onRelease = function() {_root.ball_mc.stopDrag();runBall();};ball_mc.onReleaseOutside = function() {_root.ball_mc.stopDrag();runBall();};
//---------------------------------主程序-------------------------------------------runBall();
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
每个人心里都住着一个人,或眷念,或暗恋,或想念。
文章 0 评论 0
接受
发布评论
评论(1)
给你做了个demo 看看吧
主场景:800×600
小球:30×30
小球实例命名为ball_mc
在第一帧放以下代码:
var xSpeed:Number = 0;
var ySpeed:Number = 0;
var g:Number = 1;//重力常量
var upSpeed;
var runStatus = -1;// 1为上升过程 -1为下落过程
function runBall() {
ySpeed = 0;
ball_mc.onEnterFrame = function() {
if (runStatus == -1) {
if (ball_mc._y<400) {
ySpeed += g;
ball_mc._y = ball_mc._y+ySpeed;//向下为正方向
} else {
//delete ball_mc.onEnterFrame;
upSpeed = ySpeed;
ySpeed = 0;
runStatus = 1;
}
}
if (runStatus == 1) {
if (upSpeed>0) {
upSpeed -= g;
trace(upSpeed);
ball_mc._y = ball_mc._y-upSpeed;
} else {
runStatus = -1;
}
}
};
}
//-------------------------拖拽小球----------------------------
ball_mc.onPress = function() {
_root.ball_mc.startDrag();
delete ball_mc.onEnterFrame;
};
ball_mc.onRelease = function() {
_root.ball_mc.stopDrag();
runBall();
};
ball_mc.onReleaseOutside = function() {
_root.ball_mc.stopDrag();
runBall();
};
//---------------------------------主程序-------------------------------------------
runBall();