2
我正在与一个小项目上的matter.js,尝试使用js函数添加和删除事件世界中的对象。MatterJS删除对象函数
附加功能似乎工作, remove方法只适用功能 -
var boxes = [];
function addCircle(Cid, Ccolor, Cradius) {
boxes[Cid] = Bodies.circle((w/2), (h/2), Cradius, {
density: 0.0005,
frictionAir: 0.06,
restitution: 0.3,
friction: 0.01,
render: { fillStyle: Ccolor, strokeStyle: 'rgba(0,0,0,0)',
lineWidth: 0,
}
});
boxes[Cid].angle = Math.random() * 0.5;
boxes[Cid].force.y -= 0.0001;
World.add(engine.world, boxes[Cid]);
//World.remove(engine.world, boxes[Cid]); <-- This one works
}
function removeCircle(Cid) {
//console.log(boxes[Cid]);
World.remove(engine.world, boxes[Cid]); // <-- This one doesn't
}
控制台里面添加显示错误“无法读取属性未定义‘类型’”为删除功能。 有人可以告诉我如何解决这个问题吗?任何帮助和建议都将非常可观。