issue.js鼠标单击主体 [英] matter.js mouse click on body

查看:67
本文介绍了issue.js鼠标单击主体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,如果我对something.js库有类似以下的代码:

Hello if I have some code like the following for the matter.js library :

 // 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?

Is there a way I can tell if boxA or boxB has been clicked with the mouse in the event handler ?

推荐答案

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

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

这篇关于issue.js鼠标单击主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆