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

推荐订阅源

O
OpenAI News
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
Last Week in AI
Last Week in AI
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
爱范儿
爱范儿
B
Blog
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
V
Visual Studio Blog
P
Proofpoint News Feed
小众软件
小众软件
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - 聂微东
WordPress大学
WordPress大学
博客园 - 【当耐特】
腾讯CDC
T
Tailwind CSS Blog
The Register - Security
The Register - Security
V
V2EX
S
SegmentFault 最新的问题
IT之家
IT之家
D
Docker
I
InfoQ
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Jina AI
Jina AI
The Cloudflare Blog
量子位
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
H
Help Net Security
MongoDB | Blog
MongoDB | Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
美团技术团队
B
Blog RSS Feed

博客园 - 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,在不同的设备像素比时已经表现一致