[LayaAir2]字节小游戏物理的坐标不一样,碰撞盒会比laya的小,物理的位置也不一样
代码用到了更新物理根节点去做相机跟踪
代码如下:
export default class test extends Laya.Script {
strWorldRoot:Laya.Sprite;
constructor() { super(); }
cameraPlayerOffset:Laya.Point=new Laya.Point(18,0);
cameraOffset:Laya.Point=new Laya.Point(180,570);
onEnable(): void {
Laya.Physics.I.allowSleeping = false;
this.strWorldRoot= this.owner.scene.strWorldRoot;
Laya.Physics.I.worldRoot = this.strWorldRoot;
}
onUpdate(): void {
var playerPos=new Laya.Point(this.cameraPlayerOffset.x,this.cameraPlayerOffset.y);
var spr= this.owner as Laya.Sprite;
spr.localToGlobal(playerPos);
var _x=playerPos.x - this.cameraOffset.x;//360是偏移的坐标
var _y=playerPos.y - this.cameraOffset.y;
this.strWorldRoot.x= - _x;
this.strWorldRoot.y= - _y;
Laya.Physics.I.updatePhysicsByWorldRoot();
}
}
test有源文件和字节
代码如下:
export default class test extends Laya.Script {
strWorldRoot:Laya.Sprite;
constructor() { super(); }
cameraPlayerOffset:Laya.Point=new Laya.Point(18,0);
cameraOffset:Laya.Point=new Laya.Point(180,570);
onEnable(): void {
Laya.Physics.I.allowSleeping = false;
this.strWorldRoot= this.owner.scene.strWorldRoot;
Laya.Physics.I.worldRoot = this.strWorldRoot;
}
onUpdate(): void {
var playerPos=new Laya.Point(this.cameraPlayerOffset.x,this.cameraPlayerOffset.y);
var spr= this.owner as Laya.Sprite;
spr.localToGlobal(playerPos);
var _x=playerPos.x - this.cameraOffset.x;//360是偏移的坐标
var _y=playerPos.y - this.cameraOffset.y;
this.strWorldRoot.x= - _x;
this.strWorldRoot.y= - _y;
Laya.Physics.I.updatePhysicsByWorldRoot();
}
}
test有源文件和字节
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
誌偉王
赞同来自: