cocos版本v2.4.10
想通过代码实现替换龙骨中的某一个骨骼插槽,比如把角色手里的武器插槽或者头部的头盔插槽根据角色装备数据进行切换,使用了如下代码:
if (this.node.getComponent(dragonBones.ArmatureDisplay).animationName != stand) {
this.node.getComponent(dragonBones.ArmatureDisplay).armatureName = `Armature`;
this.node.getComponent(dragonBones.ArmatureDisplay).armature().getSlot(`wpn1`).displayIndex = 0;
//↑↑↑↑↑↑↑↑↑↑错误信息就是说上面这一行
this.node.getComponent(dragonBones.ArmatureDisplay).playAnimation(`stand`, -1);
}
浏览器运行报错如下:
Uncaught TypeError: Cannot read properties of undefined (reading ‘getSlot’)
并且,我发现虽然有报错,但是切换效果却可以实现,游戏也可以正常进行。另外,我在VS里编写代码时,输入getSlot方法VS提词器没有提示。
求帮助:1.为什么报错了但是程序目的却可以实现?2.报错原因是什么?3.如何既实现程序目的,又消除该报错?