在制作游戏的过程中,常常会考虑路程,比如人物移动的路程,子弹射出的路程,你可以用最简单的办法:求弦公式,就是中学学过的:X的平方加Y的平方 = 斜边的平方,这里的斜边就是我所说的路程。
举一个例子:(折线运动)
_root.ball.onLoad = function() {
//取得小球的初始坐标;
inX = getProperty(_root.ball, _x);
inY = getProperty(_root.ball, _y);
};
_root.ball.onLoad();
//定义速度;
dx = 3;
dy = 3;
_root.ball.onEnterFrame = function() {
//使小球运动;
this._x += dx;
this._y -= dy;
//取得小球运动中的坐标
mvX = getProperty(_root.ball, _x);
mvY = getProperty(_root.ball, _y);
//运用求弦公式,当小球运动的路程大于300像素时,使dy为负数;
if (Math.sqrt((mvX-inX)*(mvX-inX)+(mvY-inY)*(mvY-inY))>=300) {
dy = -3;
}
};
源文件附件下载:
[img]/uploads/allimg/091203/2037260.gif[/img]
[url=http://www2.flash8.net/UploadTeach/200911/20091119164936709.rar]折线运动.rar[/url]
原文链接
[url=http://www2.flash8.net/teach/7948.htm]http://www2.flash8.net/teach/7948.htm[/url]
本文转自:http://www.5uflash.com/flashjiaocheng/Flashaschengxu/5204.html
举一个例子:(折线运动)
_root.ball.onLoad = function() {
//取得小球的初始坐标;
inX = getProperty(_root.ball, _x);
inY = getProperty(_root.ball, _y);
};
_root.ball.onLoad();
//定义速度;
dx = 3;
dy = 3;
_root.ball.onEnterFrame = function() {
//使小球运动;
this._x += dx;
this._y -= dy;
//取得小球运动中的坐标
mvX = getProperty(_root.ball, _x);
mvY = getProperty(_root.ball, _y);
//运用求弦公式,当小球运动的路程大于300像素时,使dy为负数;
if (Math.sqrt((mvX-inX)*(mvX-inX)+(mvY-inY)*(mvY-inY))>=300) {
dy = -3;
}
};
源文件附件下载:
[img]/uploads/allimg/091203/2037260.gif[/img]
[url=http://www2.flash8.net/UploadTeach/200911/20091119164936709.rar]折线运动.rar[/url]
原文链接
[url=http://www2.flash8.net/teach/7948.htm]http://www2.flash8.net/teach/7948.htm[/url]
本文转自:http://www.5uflash.com/flashjiaocheng/Flashaschengxu/5204.html