我创建了矩形
var options = {
isStatic: true,
angle: Math.PI * 0.15
}
elastic = Bodies.rectangle(300, 245, 75, 75, options),
将此添加到场景
World.add(_world, [elastic]);
我想在onClick上更改此obj选项。
Events.on(_engine, 'tick', function(event) {
if(_mouseConstraint.mouse.button == 0){
var options2 = {
isStatic: false,
angle: Math.PI * 0.35,
friction: 0.0001
elastic2 = Bodies.rectangle(300, 245, 75, 75, options2);
World.add(_engine.world, elastic2);
}
}
});
这就是我的尝试,如何在不使用新选项创建new的情况下在对象上设置新属性?
答案 0 :(得分:0)
解决方案我的对象跳转:)
var rect = Bodies.rectangle(300, 300, 40, 40, {id: "jumper", isStatic: false, friction: 0.001 });
World.add(_world, rect);
var jumper = Composite.get(_world, "jumper", "body");
_sceneEvents.push(
Events.on(_engine, 'mousedown', function(event) {
var mousePosition = event.mouse.position;
jumper.force = {
x: 0.001,
y: -0.01
};
console.log('mousedown at ' + mousePosition.x + ' ' + mousePosition.y);
})
);