private _body: Laya.RigidBody;
private _speed: number = 20;
let radian = this.owner.rotation * Math.PI / 180;
// 注意:需要除以 Laya.Browser.pixelRatio
let v = new Laya.Vector2(Math.cos(radian) * this._speed / Laya.Browser.pixelRatio,
Math.sin(radian) * this._speed / Laya.Browser.pixelRatio);
this._body.setVelocity(v);
根据源码:src/layaAir/laya/physics/factory/physics2DwasmFactory.ts
// physics2DwasmFactory.ts
/**
* @en Create the Box2D world.
* @zh 创建Box2D世界。
*/
start() {
this._PIXEL_RATIO = Physics2DOption.pixelRatio * Browser.pixelRatio;
//...
}
由于其在使用像素到米单位时使用了 Browser.pixelRatio (设备像素比),这会导致直接设置线性速度,会在不同的设备像素比时表现不一致
标签:pixelRatio,Laya,2d,._,LayaAir3,刚体,speed,Math,Browser From: https://www.cnblogs.com/kingBook/p/18337316