|
主题: 求助!
|
 我是小马
职务:普通成员
等级:3
金币:17.0
发贴:794
|
#12001/3/19 21:41:40
我用下面一段程序计算小球(sprite 1)下落(相当于自由落体运动)的运动过程,发现小球的运动很慢,而且是跳跃的,大家帮忙看看,主要是什么问题?
gTime = the milliseconds repeat while sprite(23).loch <= 187 sprite(1).loch = 47.0 + gGravity*sin(PI/6.0)*cos(PI/6.0)*(the milliseconds/1000 - gTime)*(the milliseconds/1000 - gTime)/2.0 sprite(1).locv = 116.0 + gGravity*sin(PI/6.0)*sin(PI/6.0)*(the milliseconds/1000 - gTime)*(the milliseconds/1000 - gTime)/2.0 updatestage end repeat
|
 jerrowolf
职务:普通成员
等级:1
金币:0.0
发贴:83
|
#22001/3/19 23:15:04
mzgjingsi在上个贴子中说 引用: 我用下面一段程序计算小球(sprite 1)下落(相当于自由落体运动)的运动过程,发现小球的运动很慢,而且是跳跃的,大家帮忙看看,主要是什么问题?
gTime = the milliseconds repeat while sprite(23).loch <= 187 sprite(1).loch = 47.0 + gGravity*sin(PI/6.0)*cos(PI/6.0)*(the milliseconds/1000 - gTime)*(the milliseconds/1000 - gTime)/2.0 sprite(1).locv = 116.0 + gGravity*sin(PI/6.0)*sin(PI/6.0)*(the milliseconds/1000 - gTime)*(the milliseconds/1000 - gTime)/2.0 updatestage end repeat
the milliseconds/1000 - gTime 这句是什么意思啊,对么?
|
 donlee
职务:普通成员
等级:1
金币:1.0
发贴:271
|
#32001/3/20 8:21:58
gTime = the milliseconds 改为gTime = the milliseconds /1000 另外,这里的sin cos似乎没什么必要,就算需要这个系数,也应放到repeat外部提前完成,这明显属于cpu密集型运算! 其它部分可能有必要计算一下比例,术语中称为归一化处理。
|
 dexn
职务:普通成员
等级:1
金币:1.0
发贴:157
|
#42001/3/20 10:12:41
也许是我水平有限,真的看不懂这段程序: 1。为什么是在repeat 里? 2。sin,cos的有什么作用? 3.sprite(23).loch<=187? 对于你提的问题: 1。小球慢,那是比例问题,你是用像素来替代米?厘米?所以适当改变便可。 2。跳跃问题,你时间用的是/1000,所以成为整数,在很短的时间(不到1秒)里,被认为没发生时间变化,也就是一秒跳一次,当然就有跳跃感了,用/1000.0看看!
|
 我是小马
职务:普通成员
等级:3
金币:17.0
发贴:794
|
#52001/3/20 12:27:09
谢谢大家的提醒,原因找到了,是因为/1000的缘故,改成/1000.0后效果好多了
谢谢!!~
|