2014-09-25 84 views
0

創建矩形Matter.js改變對象屬性的onclick

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); 
      } 
     } 
    }); 

這就是我的嘗試,如何設置對象的新屬性,而不用新的選項創建新的?

回答

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); 
     }) 

    );