版本2.3.3
代码:
onBeginContact: function (contact, selfCollider, otherCollider) {
if(otherCollider.node.name == “things”){
if(selfCollider.node.getChildByName(“things”) == null){
otherCollider.enabled = false;
let othernode = otherCollider.node;
let otherRigidBody = othernode.getComponent(cc.RigidBody);
otherRigidBody.destroy();
othernode.removeFromParent(false);
selfCollider.node.addChild(othernode);
othernode.setPosition(cc.Vec2(0,0));
}
}
},
关键报错代码:
othernode.setPosition(cc.Vec2(0,0));
报错信息:
Error
at b2Body.477.b2Body.SetTransformXY (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:96134:46)
at b2Body.477.b2Body.SetTransformVec (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:96131:16)
at cc_RigidBody.syncPosition (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:39112:23)
at cc_RigidBody._onNodePositionChanged (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:39152:14)
at EventTarget.277.proto.emit (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:44015:31)
at cc_Node.emit (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:19230:60)
at cc_Node.setPosition (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:19363:16)
at Group.onBeginContact (eval at (http://localhost:7456/preview-scripts/quick_compile.js:230:32), :119:19)
at PhysicsContact.237.PhysicsContact.emit (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:38212:35)
at PhysicsContactListener._onBeginContact [as _BeginContact] (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:38513:11)
cocos2d-js-for-preview.js:96134
Error
at b2Body.477.b2Body.SetTransformXY (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:96134:46)
at b2Body.477.b2Body.SetTransformVec (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:96131:16)
at cc_RigidBody.syncRotation (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:39123:23)
at cc_RigidBody._onNodeRotationChanged (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:39155:14)
at EventTarget.277.proto.emit (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:44015:31)
at cc_Node.emit (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:19230:60)
at cc_Node.set [as angle] (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:18603:51)
at Group.move (eval at (http://localhost:7456/preview-scripts/quick_compile.js:230:32), :80:21)
at Group.update (eval at (http://localhost:7456/preview-scripts/quick_compile.js:230:32), :102:10)
at eval (eval at createInvokeImpl (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:24228:26),
65)
物理引擎不允许碰撞时改变位置!做延迟处理。
1赞