thing.js鼠标点击身体

时间:2015-02-04 14:51:47

标签: mouse

您好,如果我有一些类似以下代码的问题:./s库:

 // create two boxes and a ground
 var boxA = Bodies.rectangle(400, 200, 80, 80);
 var boxB = Bodies.rectangle(450, 50, 80, 80);
 var ground = Bodies.rectangle(400, 610, 810, 60, { isStatic: true });

 // add all of the bodies to the world
 World.add(engine.world, [boxA, boxB, ground]);
Events.on(engine, 'tick', function(event) {
    if(mouseConstraint.mouse.button == 0){
            alert("what is clicked?");
        }
    });

有没有办法告诉我是否在事件处理程序中用鼠标点击了boxA或boxB?

1 个答案:

答案 0 :(得分:0)

mouseConstraint.body包含被单击的正文。

参见https://www.youtube.com/watch?v=W-ou_sVlTWk大约9:40