-
Creator 版本: 2.4.8
-
目标平台: GoogleChrome
-
重现方式:通过sp.spine.SkeletonBounds或sp.spine.BoundingBoxAttachment.computeWorldVertices()获取到的包围盒信息更新到碰撞体后不准确
我贴一下源码:
@property(cc.Prefab)bone_mark = null;
private spine: sp.Skeleton = null;
private spine_collider_list = [];
protected onLoad(): void {
this.spine = this.node.getComponent(sp.Skeleton); this.init_bone_message();}
init_bone_message() {
var bound = new sp.spine.SkeletonBounds(); bound.update(this.spine._skeleton, true); var slots = this.spine._skeleton.slots; for (var i = 0; i < bound.boundingBoxes.length; ++i) { var attachment: sp.spine.BoundingBoxAttachment = bound.boundingBoxes[i]; for (var j = 0; j < slots.length; ++j) { if (attachment == slots[j].attachment) { //匹配 this.spine_collider_list.push({ "attachment": attachment, "listener": this.create_bone_node(slots[j].bone.data.name) }); } } }}
find_bone(bone_name) {
var attach_util = this.spine.attachUtil; var bone_nodes = attach_util.generateAttachedNodes(bone_name); return bone_nodes[0];}
create_bone_node(bone_name) {
var bone_node = this.find_bone(bone_name); var item = Icarus.instantiate(this.bone_mark, "", bone_node, cc.Vec2.ZERO, cc.Vec2.ONE, 0, bone_name + "_mount"); return item.addComponent(SpineAutoUpdatePolygonColliderListener).init(this);}
collision_enter(other) {
//这里需要整理过滤一次避免单个物体同时触发多个部件的碰撞}
update_vertex() {
var bound = new sp.spine.SkeletonBounds(); bound.update(this.spine._skeleton, true); for (var i = 0; i < bound.boundingBoxes.length; ++i) { var attachment: sp.spine.BoundingBoxAttachment = bound.boundingBoxes[i]; for (var j = 0; j < this.spine_collider_list.length; j++) { if (this.spine_collider_list[j].attachment == attachment) { var vertex_array = []; for (var k = 0; k < bound.polygons[i].length; ++k) { vertex_array.push(bound.polygons[i][k]); } for (var k = 0; k < vertex_array.length; ++k) { if (!this.spine_collider_list[j].listener.Collider.points[k]) { this.spine_collider_list[j].listener.Collider.points.push(cc.Vec2.ZERO); } this.spine_collider_list[j].listener.Collider.points[k].x = vertex_array[k * 2]; this.spine_collider_list[j].listener.Collider.points[k].y = vertex_array[k * 2 + 1]; } } } }}
protected update(dt: number): void {
this.update_vertex();}

1赞
破案了,各位大佬可以略过这个帖子了