[0]Sprite与Collider组件位置偏移
角色身上绑定的box collider组件,角色移动过程中无法同步。
场景绑定的box collider则没有异常。
是我哪里用法不对吗?求指教!
画面移动用的
角色视图结构,atlas播放animation序列帧动画
场景使用TiledMap
场景Collider通过读取TiledMap软件生成的.json数据读取生成并加载。
场景绑定的box collider则没有异常。
是我哪里用法不对吗?求指教!
画面移动用的
this.rectangleCanvas = new Laya.Rectangle(0, 0, this.width, this.height);
this.rectangleCanvas.x = this.canvasPovit.x;
this.rectangleCanvas.y = this.canvasPovit.y;
角色视图结构,atlas播放animation序列帧动画
场景使用TiledMap
this.tMap = new Laya.TiledMap();
this.tMap.createMap(this.resourcePath, new Laya.Rectangle(0, 0, this.width, this.height), Laya.Handler.create(this, this.onMapLoaded), new Laya.Rectangle(10000, 3000, 0, 0));
场景Collider通过读取TiledMap软件生成的.json数据读取生成并加载。
this.spineCollider = new Laya.Sprite();
this.spineCollider.name = "SpineCollider";
this.basegameScene.addChild(this.spineCollider);
this.spineCollider.width = this.tMap.width;
this.spineCollider.height = this.tMap.height;
this.spineCollider.x = this.tMap.x;
this.spineCollider.y = this.tMap.y;
this.spineColliderRigid = this.spineCollider.addComponent(Laya.RigidBody);
this.spineColliderRigid.type = "static";
Laya.loader.load(this.resourcePath, Laya.Handler.create(this, this.onColliderLoaded), null, Laya.Loader.JSON);
//碰撞器加载,读取json文件
onColliderLoaded()
{
var layers = json["layers"];
console.log( layers[1].name);
for(let i = 0; i < layers.length; ++i)
{
if (layers[i].name == "SpineCollider")
{
let objects = layers[i]["objects"];
for (let index = 0; index < objects.length; index++)
{
let objData = objects[index];
let type = objData["type"];
let w = objData["width"];
let h = objData["height"];
let x = objData["x"];
let y = objData["y"];
if(type == "Box")
{
let boxCollider = this.spineCollider.addComponent(Laya.BoxCollider);
boxCollider.width = w;
boxCollider.height = h;
boxCollider.x = x;
boxCollider.y = y;
}
}
}
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
Laya_z
赞同来自:
1637908565用户
赞同来自:
附件上传不上去
百度网盘:
链接:https://pan.baidu.com/s/1AnK3C7EWTcGJFgwBpgJkLA
提取码:1234