示例的里的代码,使用的物理引擎是arcade,里面涉及运动碰撞弹跳的,会有两个方法,setBounce 和 setVelocity, 这两个方法字面意义都挺清晰的,我理解起来,花了一点时间,这里记录一下。
设置弹跳 setBounce
官方文档是是这么描述的
setBounce(x [, y])
Sets the bounce values of this body.
Bounce is the amount of restitution, or elasticity, the body has when it collides with another object. A value of 1 means that it will retain its full velocity after the rebound. A value of 0 means it will not rebound at all.
我的理解是,这是设置反弹起来后的速度保持。
例如,setBounce(1) , 原来在Y轴的速度是100,那么碰撞后,反弹的速度也是100。
设置速度 setVelocity
官方文档是这样说明的:
setVelocity(x [, y])
Sets both the horizontal and vertical velocity of the physics body
这是设置物体横向(x轴)和纵向(y轴)的速度。值的绝对值越大,速度越快。
目前没有看到这个值和时间的关系。
本文详细解析了Arcade物理引擎中setBounce和setVelocity两个关键方法的作用与使用方式。setBounce用于设置碰撞后的反弹速度比例,setVelocity则用于直接设定物体的横向与纵向速度。


被折叠的 条评论
为什么被折叠?



