惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Cisco Blogs
罗磊的独立博客
D
Docker
Microsoft Azure Blog
Microsoft Azure Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
V
V2EX
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
I
InfoQ
S
Securelist
K
Kaspersky official blog
博客园 - 司徒正美
爱范儿
爱范儿
Scott Helme
Scott Helme
B
Blog RSS Feed
H
Help Net Security
博客园 - 聂微东
Hugging Face - Blog
Hugging Face - Blog
Stack Overflow Blog
Stack Overflow Blog
AI
AI
Blog — PlanetScale
Blog — PlanetScale
Webroot Blog
Webroot Blog
P
Proofpoint News Feed
V
Visual Studio Blog
Cyberwarzone
Cyberwarzone
P
Privacy International News Feed
M
MIT News - Artificial intelligence
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
IT之家
IT之家
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
S
Security Affairs
T
Threat Research - Cisco Blogs
S
Security @ Cisco Blogs
The Register - Security
The Register - Security
F
Full Disclosure
A
Arctic Wolf
C
Check Point Blog
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
T
Tor Project blog
Latest news
Latest news
Schneier on Security
Schneier on Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - kingBook

git patch git 修改最后一次提交的日期 Win10 修改特定格式文件的右键快捷菜单 TypeScript async、 await、Promise LayaAir3.x 侦听程序退出 旋转力学例子 旋转力学公式 凹多边形碰撞检测 LayaAir3.x 侦听键盘事件 URP 阴影 TypeScript 里的 override TypeScript 类的自身类型 Unity 二维数组序列化 C# 匿名对象、动态属性 Cocos Creator 安卓模拟器中无法运行 Unity Editor 保存图片、缩放纹理 LayaAir3.x 物理2D碰撞事件 TypeScirpt 声明Map类型变量 TypeScript 声明函数类型变量
LayaAir3.2.0-beta.2 设置2d刚体线性速度,在不同设备(分辨率)下,表现不一致的问题
kingBook · 2024-08-01 · via 博客园 - kingBook
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 (设备像素比),这会导致直接设置线性速度,会在不同的设备像素比时表现不一致
注: 在 LayaAir3.2.0-beta.3 官方已修复了此问题,不再需要除以 Laya.Browser.pixelRatio,在不同的设备像素比时已经表现一致