collision detection fabrics js

廉价感情. 提交于 2019-12-11 11:53:55

问题


I am using fabric js, i use the following function to put an image on canvas, when i click on canvas an image is put on that location, i want to know if there is way that i can check weather there is something already present at location where i am clicking especially if there is another image or not

  document.getElementById("door").onclick = function () {

            canvas.on('mouse:down', function (o) {
                fabric.Image.fromURL('http://localhost:60099/Images/door.png', function (img) {
                    var pointer = canvas.getPointer(o.e);

                    logo = img.set({ left: pointer.x , top: pointer.y  })

                    canvas.add(logo);
                    canvas.item(objC).lockMovementY = true;
                    canvas.item(objC).lockMovementX = true;
                    canvas.renderAll();

                });

            });

        }

回答1:


Collisions can be detected with the fabric.js 'intersectsWithObject' function. Consider their 'intersection' example:

http://fabricjs.com/intersection



来源:https://stackoverflow.com/questions/23258284/collision-detection-fabrics-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!